Lesson 2 Arduino Projects Book

In Lesson 2, i had to create a circuit that allows for the divergence of electricity between two red LED’s and one green LED.

By hitting the button you turned the green LED on while turning off the two red LED’s.

IMG_20140207_204904off

IMG_20140207_204943on

All in all quite good and fairly straight forward, except the extra timing code added in at the end.

IMG_20140207_205129

int switchState = 0;
void setup(){
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop(){
switchState = digitalRead(2);
// this program is for exercise 2 and should light up some LEDs 2 red and one green

if (switchState == LOW) {
// the button is not pressed

digitalWrite(3, HIGH); // Green LED
digitalWrite(4, LOW); // Red LED
digitalWrite(5, LOW); // Red LED
}
else { // the button is pressed
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);

}
} // go back to the beginning of the loop yo

Leave a comment