Button Cycle LED Circle Bug Hunt! Test your Troubleshooting.

For your final bug hunt, it will be easiest to hunt down the problem by uploading and then playing with the code. What is different from the way the project worked? Now that you’ve built up some troubleshooting instincts, can you hunt down the bugs without the hint?

/* Buggy: Use button 12 to turn on more of your circle LEDs and button 11 to turn them off one at a time. */ int pressCount = 0; //Variable to keep track of which LEDs are on and off void setup(){ pinMode(11,INPUT_PULLUP); //buttons pinMode(12,INPUT_PULLUP); pinMode(3,OUTPUT); //LEDs pinMode(4,OUTPUT); pinMode(5,OUTPUT); pinMode(6,OUTPUT); } void loop(){ if(digitalRead(12)==LOW){ //if button 12 pressed, increase PressCount variable by 1 pressCount++; delay(25); //delay 250 milliseconds so a single press doesn't count multiple times } if(digitalRead(11)==LOW){ //if button 11 pressed, decrease PressCount variable by 1 pressCount--; delay(25); } if(pressCount>4){ //Don't let pressCount go above 4. pressCount=4; } if(pressCount<0){ //Don't let the pressCount variable go into negative #s pressCount=0; } if(pressCount==1){ //When pressCount is 1, turn on LED3 and off everything else digitalWrite(3,HIGH); digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW); } else if(pressCount ==2){ //When pressCount is 2, turn on LED3 and off 5 and 6 digitalWrite(4,HIGH); digitalWrite(5,LOW); digitalWrite(6,LOW); } else if(pressCount ==3){ //When pressCount is 3, turn on LED5 and off 6 digitalWrite(5,HIGH); digitalWrite(6,LOW); } else if(pressCount ==4){ //When pressCount is 4, turn everything on digitalWrite(6,HIGH); } else{ digitalWrite(3,LOW); //if pressCount isn't 1,2,3,or 4, turn everything off. digitalWrite(4,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW); } } // (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Need a hint? Click here.