Created
May 19, 2015 17:55
-
-
Save realjax/255cf75983234ccb54ac 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
/* | |
DigitalReadSerial | |
Reads a digital input on pin 2, prints the result to the serial monitor | |
This example code is in the public domain. | |
*/ | |
// digital pin 2 has a pushbutton attached to it. Give it a name: | |
int pushButton = 2; | |
int buttonStateHistory = 0 ; | |
int ledIndex = 0; | |
int pins[] = {5,6,7,8,9,10,11,12}; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
// initialize serial communication at 9600 bits per second: | |
Serial.begin(9600); | |
pinMode(pushButton, INPUT); | |
for (int i = 0; i < sizeof(pins); i++){ | |
pinMode(i, OUTPUT); | |
} | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
// read the input pin: | |
int buttonState = digitalRead(pushButton); | |
if (buttonState == HIGH) { | |
if (buttonState == buttonStateHistory ){ | |
digitalWrite(pins[ledIndex], HIGH); | |
ledIndex++; | |
}else{ | |
ledIndex = 0; | |
digitalWrite(pins[ledIndex], HIGH); | |
} | |
} else { | |
for (int i = 0; i < sizeof(pins); i++){ | |
digitalWrite(i, HIGH); | |
} | |
} | |
buttonStateHistory = buttonState; | |
// print out the state of the button: | |
//Serial.println(buttonState); | |
delay(200); // delay in between reads for stability | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment