Arduino - 如何多线程这个应用程序

时间:2012-09-30 18:44:29

标签: arduino

我正在写一个车库门开启器和监视器。

显示器通过RF(315 MHz)上的另一个Arduino接收门状态。下面的代码有效,但我觉得每次向服务器发出请求打开门时都不需要检查状态。有没有办法将代码分开,以便每隔20秒检查门的状态,并且车库的开启和关闭是按需的?

这是代码: https://github.com/dhysong/ArduinoGarageOpener/blob/master/src/GarageDoorOpener/GarageDoorOpener.ino

1 个答案:

答案 0 :(得分:2)

根据这篇文章:http://arduino.cc/forum/index.php/topic,5686.0.html

我能够为我的应用添加类似多线程的功能。源代码已更新以反映更改。

以下是相关内容:

boolean cycleCheck(unsigned long *lastMillis, unsigned int cycle) 
{
  unsigned long currentMillis = millis();
  if(currentMillis - *lastMillis >= cycle)
{
  *lastMillis = currentMillis;
  return true;
 }
else
  return false;
}

以下是可能受益的任何人的github代码:https://github.com/dhysong/ArduinoGarageOpener/blob/master/src/GarageDoorOpener/GarageDoorOpener.ino

相关问题