Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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