Bug Hunt! Test your Troubleshooting.

Here’s how Bug Hunts work:

We’ve taken the example code from the last project and inserted errors into it. These errors might be spelling problems, syntax, or we might have changed up how the program works altogether!

The goal of the Bug Hunt is to find and fix the errors so that when you upload the code, it runs just like the example code did on the project page.

Try these steps in order to solve a Bug Hunt:

1) Look over the code closely first, looking for anything that is out of place. We recommend you do this first to build up your ‘bug hunting instincts’.

2) Press ‘Upload the Code’ with your board plugged in and the circuit built. The code won’t work, but it will show you the errors that the computer found - these will pop up in a box just below the code editor. These clues are sometimes vague or confusing, but they may help you find out where the problem is.

3) Check your code references, especially for the functions that have turned red when you hit “Upload”. Compare the syntax of your reference book to the syntax in your code editor here.

After you’ve fixed the bug and the code is working again, hit ‘Restore’ so you can see the code how it was before you fixed it. Is the bug obvious to you now? Reviewing like this will make it easier to find bugs in future programs!

Get stuck? Click on ‘Need a Hint?’ below. It will provide a clue about what’s wrong in this program.

/* Buggy: Set up 3 buttons to correspond to each color from the RGB LED Pressing any single button shows one color. Pressing multiple buttons mixes colors! */ void setup() { pinMode(8,INPUT_PULLUP); //button pinMode(9,INPUT_PULLUP); //button pinMode(10,INPUT_PULLUP); //button pinMode(5,OUTPUT); //one leg of the RGB LED pinMode(6,OUTPUT); //one leg of the RGB LED pinMode(7,OUTPUT); //one leg of the RGB LED } void loop() { if(digitalRead(8)==LOW){ //if button 8 is pressed... digitalWrite(5,HIGH); //turn on LED 5 } else{ //otherwise, if button 8 is not pressed... digitalWrite(5,LOW); //turn off port 5 } if(digitalRead(9)==HIGH){ //if button 9 is pressed... digitalWrite(6,HIGH); //LED 6 on } else{ //otherwise.... digitalWrite(6,LOW); //LED 6 is off } if(digitalRead(10)==LOW){ //if button 10 is pressed... digitalWrite(7,HIGH); //LED 7 is on } else{ //otherwise.... digitalWrite(7,LOW); //LED 7 is off } } // (c) 2021 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Need a hint? Click here.