简体   繁体   中英

Multi thread problem with loop on ESP8266

I'm using Nodemcu for my IoT project and I should use PHP with that. I'm trying to changing funcs, when I press the button on web site. My func1 has 1000ms delay with millis. func2 has a 360000ms delay, so I can't change func2 to func1 when I want to. I tried so many ways, how can I do that?

My code is like this:

void func1() {
  // code for manuel GPIO control 
  // millis....
}

void func2() {
  // code for automatic GPIO control 
  // millis....
}

void loop() {
  // millis....
  if (payload == 1) {
    func1();
  } else if (payload == 0) {
    func2();
  }
}

Arduino does not support multi-threading, but you can use different programming technique to make your program to work without blocking, for example Blink Without Delay

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM