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. 

/* * Use a single button to flash the brake lights and beep the horn */ void setup(){ pinMode(11,INPUT_PULLUP); //button to activate flashing and beeping pinMode(7,OUTPUT); //brake light pinMode(2,OUTPUT); //speaker / horn } void loop(){ if(digitalRead(11)==LOW){digitalWrite(7,HIGH); tone(2,500); delay(300);digitalWrite(7,LOW); //turn off the light noTone(2); //silence the tone on pin 2 delay(300);} else{//if the button is not pressed... digitalWrite(7,LOW); noTone(2); } } //This curly brace closes the void loop // (c) 2022 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Need a hint? Click here.