Created
August 16, 2018 09:01
Arduino code for Blinking an LED without Delay.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int ledPin = 13; | |
int ledState = LOW; | |
unsigned long previousMillis = 0; | |
const long interval = 1000; | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); | |
} | |
void loop() | |
{ | |
unsigned long currentMillis = millis(); | |
if (currentMillis - previousMillis >= interval) | |
{ | |
previousMillis = currentMillis; | |
if (ledState == LOW) | |
{ | |
ledState = HIGH; | |
} | |
else | |
{ | |
ledState = LOW; | |
} | |
digitalWrite(ledPin, ledState); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment