Piano Button Pitch Changer Bug Hunt! Test your Troubleshooting.

If you can spot this bug without uploading, you can practically see into the future! You may even have to play with the uploaded buggy code for a while to see what’s wrong with it.

//Buggy: Raise the tone's pitch when button 9 is pressed, lower it when button 2 is pressed int pitch = 40; void setup(){ pinMode(10,OUTPUT); //speaker set to OUTPUT pinMode(9,INPUT_PULLUP); //button that will raise the pitch of the tone pinMode(2,INPUT_PULLUP); //button that will lower the pitch of the tone } void loop(){ tone(10,pitch); //Play a tone of 'pitch' every time the loop runs. The value of 'pitch' will change if(digitalRead(9)==LOW){ //If button 9 is pressed, sending a LOW signal... pitch++; //increase the value of 'pitch' by one with the ++ command delay(2); //delay 2 milliseconds before running the rest of the void loop } else if(digitalRead(2)==LOW){ //if button 2 is pressed... pitch--; //decrease the value of 'pitch' by one with the -- command delay(2); //wait 2 milliseconds } } // (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Need a hint? Click here.