Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sighrobot
Created September 13, 2013 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sighrobot/6554948 to your computer and use it in GitHub Desktop.
Save sighrobot/6554948 to your computer and use it in GitHub Desktop.
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