Big Red Button (PANIC)

FRUSTRATION!!
Assignment No. 2 Photo

ICM: Assignment No. 2 from Nicole Kim on Vimeo.

For my program, I had three switches and three LEDs. I wanted to have switch A turn on the red LED, switch B to turn on the green LED, and switches A and B when pressed simultaneously to turn on the yellow LED. The big red button on the third switch would make the LEDs blink sequentially (panic!!).

For some reason when I coded the yellow LED separately from the rest of the program, I got it to work when both switches were turned on. I even got the code to work with the whole system one time, but then I stupidly fidgeted with the wiring, so the only-yellow-LED code doesn’t work! Frustration!!

void setup(){
pinMode(8,INPUT);
pinMode(7,INPUT);
pinMode(6,INPUT);
pinMode(5,OUTPUT); //red light
pinMode(4,OUTPUT); //yellow light
pinMode(3,OUTPUT); //green light
}

void loop(){
if(digitalRead(8)==HIGH && digitalRead(7)==HIGH){
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(3,LOW);
}else{
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(3,LOW);
}

(Code for the yellow LED- why do green and red LEDs turn on as well?!)

If anyone wants a little extra homework and wants to help me figure this out later….aaaarggg!! (But I’m still excited && proud of my code this week!)

 

Leave a Reply