Aduino flashing lights project
![Picture](/uploads/1/3/4/7/13471609/__5129694.jpg)
This was our arduino project. We connected a button as an input and 4 led lights as out puts. whenever the button was pressed the LEDs would light up. and when the button was released it turned off.
the code
![Picture](/uploads/1/3/4/7/13471609/__7931889.jpg)
my partner was Ericka. the code we made was
int buttonPin = 12;
int buttonState = 0;
int ledPin03 = 11; // Same for 11 through 7
int ledPin04 = 10;
int ledPin05 = 9;
int ledPin06 = 8;
int delayTime = 100; // 1000 milliseconds = 1 second
void setup() {
//declaring pins as inputs and outputs
pinMode(buttonPin, INPUT); //button attached to pin 12
pinMode(ledPin03, OUTPUT); // Digital Pin 11 will now be an output
pinMode(ledPin04, OUTPUT); // Digital Pin 10 will now be an output
pinMode(ledPin05, OUTPUT); // Digital Pin 9 will now be an output
pinMode(ledPin06, OUTPUT); // Digital Pin 8 will now be an output
}
void loop() {
//check the current state of the button
buttonState = digitalRead(buttonPin);
//if the button IS pressed
if(buttonState == HIGH){ // HIGH = pressed
digitalWrite(ledPin03, HIGH); // set the LED on
digitalWrite(ledPin04, LOW); // set the LED off
digitalWrite(ledPin05, HIGH); // set the LED on
digitalWrite(ledPin06, LOW); // set the LED off
delay(delayTime); // wait for a second
digitalWrite(ledPin03, LOW); // set the LED off
digitalWrite(ledPin04, HIGH); // set the LED on
digitalWrite(ledPin05, LOW); // set the LED off
digitalWrite(ledPin06, HIGH); // set the LED on
delay(delayTime); // wait for a second
}
//if the button IS NOT pressed
else if(buttonState == LOW){ // LOW = NOT pressed
digitalWrite(ledPin03, LOW); // set the LED off
digitalWrite(ledPin04, LOW); // set the LED off
digitalWrite(ledPin05, LOW); // set the LED off
digitalWrite(ledPin06, LOW); // set the LED off
}
}
int buttonPin = 12;
int buttonState = 0;
int ledPin03 = 11; // Same for 11 through 7
int ledPin04 = 10;
int ledPin05 = 9;
int ledPin06 = 8;
int delayTime = 100; // 1000 milliseconds = 1 second
void setup() {
//declaring pins as inputs and outputs
pinMode(buttonPin, INPUT); //button attached to pin 12
pinMode(ledPin03, OUTPUT); // Digital Pin 11 will now be an output
pinMode(ledPin04, OUTPUT); // Digital Pin 10 will now be an output
pinMode(ledPin05, OUTPUT); // Digital Pin 9 will now be an output
pinMode(ledPin06, OUTPUT); // Digital Pin 8 will now be an output
}
void loop() {
//check the current state of the button
buttonState = digitalRead(buttonPin);
//if the button IS pressed
if(buttonState == HIGH){ // HIGH = pressed
digitalWrite(ledPin03, HIGH); // set the LED on
digitalWrite(ledPin04, LOW); // set the LED off
digitalWrite(ledPin05, HIGH); // set the LED on
digitalWrite(ledPin06, LOW); // set the LED off
delay(delayTime); // wait for a second
digitalWrite(ledPin03, LOW); // set the LED off
digitalWrite(ledPin04, HIGH); // set the LED on
digitalWrite(ledPin05, LOW); // set the LED off
digitalWrite(ledPin06, HIGH); // set the LED on
delay(delayTime); // wait for a second
}
//if the button IS NOT pressed
else if(buttonState == LOW){ // LOW = NOT pressed
digitalWrite(ledPin03, LOW); // set the LED off
digitalWrite(ledPin04, LOW); // set the LED off
digitalWrite(ledPin05, LOW); // set the LED off
digitalWrite(ledPin06, LOW); // set the LED off
}
}