Makerino

Blink without delay

May 26th, 2019
329
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int ledPin =  LED_BUILTIN;
  2. int ledstatus = LOW;          
  3. unsigned long previousMillis = 0;        
  4. const long interval = 500;          
  5.  
  6. void setup() {
  7.  
  8.   pinMode(ledPin, OUTPUT);
  9. }
  10.  
  11. void loop() {
  12.  
  13.   unsigned long currentMillis = millis();
  14.  
  15.   if (currentMillis - previousMillis >= interval) {
  16.     previousMillis = currentMillis;
  17.     if (ledstatus == LOW) {
  18.       ledstatus = HIGH;
  19.     } else {
  20.       ledstatus = LOW;
  21.     }
  22.     digitalWrite(ledPin, ledstatus);
  23.   }
  24. }
RAW Paste Data