Skip to content

Instantly share code, notes, and snippets.

@HoughIO
Created December 10, 2014 23:05
Show Gist options
  • Save HoughIO/2e04d736585e43377860 to your computer and use it in GitHub Desktop.
Save HoughIO/2e04d736585e43377860 to your computer and use it in GitHub Desktop.
Ardunio
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
const int buttonPin = 6; // the number of the pushbutton pin
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
int led1flag = true;
int led2flag = true;
int led3flag = true;
int led4flag = true;
int led5flag = true;
int ledState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
loop(); {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
digitalWrite(led1, HIGH); // turn LED1 on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led1, LOW); // turn LED1 off by making the voltage LOW
digitalWrite(led2, HIGH); // turn LED2 on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led2, LOW); // turn LED2 off by making the voltage LOW
digitalWrite(led3, HIGH); // turn LED3 on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led3, LOW); // turn LED3 off by making the voltage LOW
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
ledState = !ledState;
int led3flag = false;
break;
}
}
}
// set the LED:
digitalWrite(led3, ledState);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
digitalWrite(led4, HIGH); // turn LED4 on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led4, LOW); // turn LED4 off by making the voltage LOW
digitalWrite(led5, HIGH); // turn LED5 on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led5, LOW); // turn LED5 off by making the voltage LOW
digitalWrite(led4, HIGH); // turn LED4 on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led4, LOW); // turn LED4 off by making the voltage LOW
digitalWrite(led3, HIGH); // turn LED3 on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led3, LOW); // turn LED3 off by making the voltage LOW
digitalWrite(led2, HIGH); // turn LED2 on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led2, LOW) // turn LED2 off by making the voltage LOW
}
if (led3flag) == (false) {
ledState = !ledState;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment