mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Change to reduce call to millis() by Paul Stoffregen
This commit is contained in:
@ -12,8 +12,8 @@
|
||||
|
||||
created 2005
|
||||
by David A. Mellis
|
||||
modified 17 Jun 2009
|
||||
by Tom Igoe
|
||||
modified 8 Feb 2010
|
||||
by Paul Stoffregen
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
|
||||
*/
|
||||
@ -42,9 +42,11 @@ void loop()
|
||||
// check to see if it's time to blink the LED; that is, is the difference
|
||||
// between the current time and last time we blinked the LED bigger than
|
||||
// the interval at which we want to blink the LED.
|
||||
if (millis() - previousMillis > interval) {
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
if(currentMillis - previousMillis > interval) {
|
||||
// save the last time you blinked the LED
|
||||
previousMillis = millis();
|
||||
previousMillis = currentMillis;
|
||||
|
||||
// if the LED is off turn it on and vice-versa:
|
||||
if (ledState == LOW)
|
||||
@ -56,3 +58,4 @@ void loop()
|
||||
digitalWrite(ledPin, ledState);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user