This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
start [2014/01/25 11:17] admin created |
start [2022/04/19 14:06] (current) admin [Millis not Delay] |
||
---|---|---|---|
Line 1: | Line 1: | ||
Good stuff to follow. | Good stuff to follow. | ||
+ | ====== Millis not Delay ====== | ||
+ | |||
+ | <code> | ||
+ | unsigned long eventInterval; | ||
+ | unsigned long previousTime; | ||
+ | void setup() | ||
+ | { | ||
+ | eventInterval=5000; // 5 seconds | ||
+ | previousTime=millis(); | ||
+ | } | ||
+ | void loop() { | ||
+ | unsigned long currentTime = millis(); | ||
+ | |||
+ | /* This is the event */ | ||
+ | if (currentTime - previousTime >= eventInterval) { | ||
+ | /* Event code */ | ||
+ | Serial.println("Timeout"); | ||
+ | | ||
+ | /* Update the timing for the next time around */ | ||
+ | previousTime = currentTime; | ||
+ | } | ||
+ | } | ||
+ | </code> |