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. 

/* * Press a button that 'locks' the headlight on until you press it again */ int pressCount = 0; //create an 'integer' variable called 'pressCount' void setup() { pinMode(4,OUTPUT); // headlight pinMode(8,INPUT_PULLUP); //button to control headlight } void loop() { if(digitalRead(8)==LOW){ //if the button is pressed pressCount == pressCount + 1; //increase pressCount by 1 delay(250); //wait 250 milliseconds before increasing pressCount again } if(pressCount == 1){ //if pressCount is equal to 1 digitalWrite(4,HIGH); //the headlight is on } else{ //otherwise, turn the headlight off and set pressCount to 0 digitalWrite(4,LOW); pressCount == 0; } } //This brace closes the void loop // (c) 2022 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Need a hint? Click here.