//Using Millis() for LED ON and OFF
int ledPin = 2; // ESP 32
int ledState = LOW;
long interval = 1000;
long previousMillis = 0;
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);
}
}
No comments:
Post a Comment