Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned long previousMillis = 0;
- unsigned long stoptime = 2000;
- unsigned long currentMillis = millis();
- int led = 13;
- int ledstate = LOW;
- boolean timerOn = false; // know when to check for the timer
- boolean toogleLED = true; // set a flag so the switch only happens once
- void setup(){
- Serial.begin(9600); // Debug will be disabled in final versions
- pinMode(led, OUTPUT);
- digitalWrite(led, LOW);
- delay(5000);
- Serial.println("...Program start\n");
- }
- void loop() {
- currentMillis = millis(); // get current time
- digitalWrite(led, ledstate); // always update the pin
- if((currentMillis - previousMillis >= stoptime) && (timerOn == true)) {
- // we hit the interval time, stoptime
- Serial.println("Timer has expired, Turning off LED");
- ledstate = LOW;
- timerOn = false;
- }
- if ((ledstate == LOW) && (toogleLED == true)) {
- Serial.println("Turning on LED, Lets see if it turns off in 2 seconds");
- ledstate = HIGH;
- previousMillis = currentMillis; // store CURRENT time to compare against
- toogleLED = false;
- timerOn = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement