Created
September 13, 2013 19:25
-
-
Save sighrobot/6554948 to your computer and use it in GitHub Desktop.
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
long previousMillis = 0; // store last time LED was updated | |
long interval = 100; // blink interval (milliseconds) | |
void setup() { | |
pinMode(2, INPUT); | |
pinMode(3, OUTPUT); | |
pinMode(4, OUTPUT); | |
digitalWrite(4, HIGH); // start with one LED on | |
} | |
void loop() { | |
if (digitalRead(2) == HIGH) { | |
if (interval == 100) { | |
interval = 250; | |
} | |
else if (interval == 250) { | |
interval = 500; | |
} | |
else if (interval == 500) { | |
interval = 100; | |
} | |
delay(500); | |
} | |
unsigned long currentMillis = millis(); | |
if(currentMillis - previousMillis > interval) { | |
// store the last time LEDs blinked | |
previousMillis = currentMillis; | |
// alternate the LEDs | |
if (digitalRead(3) == HIGH) { | |
digitalWrite(3, LOW); | |
} | |
else { | |
digitalWrite(3, HIGH); | |
} | |
if (digitalRead(4) == HIGH) { | |
digitalWrite(4, LOW); | |
} | |
else { | |
digitalWrite(4, HIGH); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment