Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long previousMillis = 0;
- long stoptime = 2000;
- unsigned long currentMillis = millis();
- int led = 13;
- int ledstate = LOW;
- void setup(){
- Serial.begin(9600); // Debug will be disabled in final versions
- pinMode(led, OUTPUT);
- digitalWrite(led, LOW);
- delay(5000);
- }
- void loop(){
- previousMillis = currentMillis;
- if(ledstate == LOW){
- Serial.println("Turning on LED, Lets see if it turns off in 2 seconds");
- digitalWrite(led, HIGH);
- ledstate = HIGH;
- }
- else if(currentMillis - previousMillis > stoptime) {
- Serial.println("Timer has expired, Turning off LED");
- digitalWrite(led, LOW );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement