Set the execution time, click “Start”, start the countdown, the countdown ends, automatically terminate the operation (power), shut down the device (power).

#define BLINKER_PRINT Serial
#define BLINKER_WIFI


#include <Blinker.h>

char auth[] = "* * * * * * *";
char ssid[] = "* * * * * * *";
char pswd[] = "* * * * * * *";

// Create a new component object
BlinkerButton Button1("btn1");
BlinkerButton Button2("btn2");
BlinkerNumber Number1("num1");
BlinkerText Text1("tex1");
BlinkerText Text2("tex2");
BlinkerText Text3("tex3");
BlinkerText Text4("tex4");
BlinkerText Text5("tex5");
BlinkerSlider Slider1("ran1");
BlinkerNumber Number_1("num1");
int counter = 0;
int ran=20;
int start_time=0;
int end_time=0;
int countDown=0;

bool run_state =false;
bool btn_state =true;
bool btn_end =false;
bool ran_state =true;
// Press the key to execute the function
void button1_callback(const String & state) {

  if(btn_state){
    BLINKER_LOG("get button state: ", state);
    Button1.color("#6a5ae2");
    Button1.text("Running");
    Button1.print();
    
    Button2.color("#eee");
    Button2.text("Termination");
    Button2.print();
    
    Blinker.vibrate(255);  
    run_state=true;
    btn_state=false;
    btn_end=true;
    ran_state=false;
    start_time=millis();
    
    Text1.print(start_time);
    digitalWrite(0,LOW);
    BLINKER_LOG("get button state:on", state);
    Blinker.vibrate(255); }}void onTimer(a)
{
  end_time=(ran+3) *1000 + start_time;
  
// Text1.print( ceil((millis()-start_time)/1000));
  if(run_state){

    if(ceil((millis()-start_time)/1000)<=ran){
      countDown=ceil(ran- ceil((millis()-start_time)/1000));
      Text2.print(countDown);
      Number1.print(countDown- 1);
    }else{
      Text2.print(0);
      Number1.print(0); }}if( end_time < millis() && run_state){
      counter++;
      Button1.color("#eee");
      Button1.text("Run");
      Button1.print();
  
      Button2.color("#6a5ae2");
      Button2.text("Termination");
      Button2.print();
      
      run_state=false;
      btn_state=true;
      btn_end=false;
      ran_state=true;

  
      digitalWrite(0,HIGH);
      Blinker.vibrate(255);  
    }


  
  
  Text3.print(run_state);
  Blinker.print("counter", start_time);
  Text4.print(btn_end);
  Text5.print(btn_state);
  Blinker.print("counter", end_time);
  
  
}


void button2_callback(const String & state) {

  if(btn_end){
    BLINKER_LOG("get button state: ", state);
    Button2.color("#6a5ae2");
    Button2.text("Termination");
    Button2.print();

    Button1.color("#eee");
    Button1.text("Run");
    Button1.print();

    run_state=false;
    btn_state=true;
    btn_end=false;
    ran_state=true;
    digitalWrite(0,HIGH);
    Text2.print(0);
    Number1.print(0);
    BLINKER_LOG("get button state:off", state);
    Blinker.vibrate(255);  
  }
   
// digitalWrite(LED_BUILTIN, ! digitalRead(LED_BUILTIN));
}


void slider1_callback(int32_t value)
{
    if(ran_state){
      BLINKER_LOG("get slider value: ", value);
      ran = value;
      Blinker.vibrate(255);  
      Slider1.print(value);
    
    }else{ Slider1.print(ran); }}// If an unbound component is fired, its contents are executed
void dataRead(const String & data)
{ 
    BLINKER_LOG("Blinker readString: ", data);
    counter++;
    Blinker.print("counter", counter);
    Number1.print(counter);
 
}

void setup(a) {
    // Initialize the serial port
    Serial.begin(115200);

    #if defined(BLINKER_PRINT)
        BLINKER_DEBUG.stream(BLINKER_PRINT);
    #endif
    
    // Initializes LED IO
    pinMode(0, OUTPUT);              // Define the IO port as the output
    digitalWrite(0, HIGH);           // Set IO to high by default
// pinMode(LED_BUILTIN, OUTPUT);
// digitalWrite(LED_BUILTIN, HIGH);
    // Initialize Blinker
    Blinker.begin(auth, ssid, pswd);
    Blinker.attachData(dataRead);
    Button1.attach(button1_callback);
    Button2.attach(button2_callback);
    Slider1.attach(slider1_callback);

}

void loop(a) {
    Blinker.run();
    onTimer();
}

Copy the code

There is no library that references timers, so MsTimer2 has a simple timer implementation in the loop

Arduino download here www.arduino.cn/thread-5838… Don’t use version 2.0

File “preference” additional development board manager url to fill the arduino.esp8266.com/stable/pack…

Install the blinker Arduino libraries diandeng. Tech/SDK/blinker… Windows: Unzip the downloaded Blinker library to my computer > Documentation >Arduino> Libraries folder

Document diandeng. Tech/doc/getting…

Install ESP8266 in development board

Data that component also works with delays…

I shallow c foundation ah, implementation function is good, regardless of its code elegant or not elegant.