Rocket Random Sounds Bug Hunt! Test your Troubleshooting.

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

/* Buggy: Make a random beep on the speaker when you press button 12. */ void setup(){ pinMode(2,OUTPUT);//Speaker pinMode(12,INPUT_PULLUP); //Button } void loop(){ if(digitalRead(12)==LOW){ //if the button sends a LOW (pressed) signal tone(2,random(50,50)); //play a tone randomly between 50 and 1000 hertz on pin 2 (speaker) delay(50); //a small delay ensures it doesn't just sound like static } else{ //otherwise if no LOW signal from button noTone(2); //stop any tones that are playing on the speaker } } // (c) 2018 Let's Start Coding. License:

Need a hint? Click here.