Bug Hunt! Test your Troubleshooting.

You may have already run into some errors in modifying or writing your own code. Don't worry, studies have shown that almost half of all code 'compiles' result in an error! 

The code below has some errors sprinkled in it. Before you run the code, read through it and look for the errors, called bugs. Can you find them? Try to fix each one and then see if the code runs. 

/* * Make the horn beep a higher tone every time it's pressed with a variable */ int pitch = 100; //an integer type variable named 'pitch' with a starting value of 100 void setup(){ pinMode(9,INPUT_PULLUP); // the horn button pinMode(2,OUTPUT); // Code Car speaker } void loop(){ if(digitalRead(9)==LOW){ //if the horn button is pressed... tone(2,pitch); //use the value of the variable 'pitch' as the hertz int pitch = pitch + 50; //increase pitch by 50 delay(500); //delay 500 milliseconds before checking the 'if' again } else{ noTone(2); } } // (c) 2022 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Need a hint? Click here.