Piano Random Note Button Bug Hunt! Test your Troubleshooting.

This code will upload to your Code Piano, but there is something off about the ‘randomness’ of the tones.

// Buggy: Play a stream of random tones when button 6 on the Piano is pressed void setup(){ pinMode(10,OUTPUT); //speaker set to OUTPUT pinMode(6,INPUT_PULLUP); //button that will activate tones } void loop(){ if(digitalRead(6)==LOW){ //If button 6 is pressed, sending a LOW signal... tone(10,random(800,40)); //... play a tone ranging from 40 to 799 on the speaker delay(100); //Wait 100 milliseconds before continuing through the void loop } else{ //in all other cases (when button 6 is not pressed)... noTone(10); //send a noTone command to stop any tones from playing } } // (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Need a hint? Click here.