@Jack, check out the elapsedMillis library in the web IDE. With it you can create millisecond “timers” that magically run in the background (they don’t but it appears that way).
The way you do “multiple” processes are you call them is really cascaded timers triggering at their designated intervals. For example:
elapsedMillis event1;
elapsedMillis event2;
setup()
{
event1 = 0; //reset the event "timers"
event2 = 0;
}
loop()
{
if (event1 > 3) // 4ms or more have passed
{
checkDoor()
event1 = 0; // reset event timer
}
if(event2 > 7000) // 7000ms or more (7sec) have passed
{
toggleLed()
event2 = 0; //reset event timer
}
}
You have the right idead. There are a couple of catches however:
- The code called within the event can’t run longer than the shortest event time you use
- When loop() ends, it will call the background firmware which may run for several milliseconds (until the new firmware for both the Core and the Photon is released) so events may not be accurate unless you turn off the Cloud connection.
