Rocket Advanced Blaster SOunds 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. 

/* Buggy: Fire laser 7 when you press button 11. * Fire laser 8 when you press button 12. * Use the speaker to add a tone when the laser fires. */ void setup() { pinMode(2,OUTPUT); //speaker pinMode(7,OUTPUT); //blaster LED 7 pinMode(8,OUTPUT); //blaster LED 8 pinMode(11,INPUT_PULLUP); //button 11 pinMode(12,INPUT_PULLUP); //button 12 } void loop() { if(digitalRead(11)==HIGH){ //if button 11 is pressed digitalWrite(7,HIGH); //turn on LED 7 //A fast falling tone makes a better laser sound (like the laser 'bullet' is getting further away) than a single tone does. for(int i=800;i>500;i--){ //Starting at 800 and decreasing to 500 tone(2,i); //play the tone with pitch equal to variable 'i' delay(1); //delay 1 millisecond before changing the pitch and playing again } } else if(digitalRead(12)==HIGH){ //if button 12 is pressed digitalWrite(8,HIGH); // turn on LED 8 // This tone falls from 1000 to 700, playing a different tone every 1 millsecond for(int i=1000;i>700;i--){ // Starting at 1000 and decreasing to 700 tone(2,i); //play the tone with pitch equal to variable 'i' delay(1); //delay 1 millsecond } } else{ //Otherwise if no buttons are pressed digitalWrite(7,LOW); //turn off the LEDs digitalWrite(8,LOW); noTone(2); //stop the tone on the speaker } }
 



Need a hint? Click here.