Test the basics of your rocket’s audio messaging center with a steady beep!

The code in the editor below already works Just plug in your Code Rocket and press upload to see what it does! Tinker with it and make changes to see what each line of code controls.

//Beep the speaker on and off once per second void setup(){ pinMode(2,OUTPUT); //Set the speaker as an 'OUTPUT' } void loop(){ tone(2,600); //tone requires the pin # (2 for speaker), and the pitch you want to play delay(1000); //delay the program for 1 second with the speaker playing noTone(2); //noTone only requires the pin of the speaker delay(1000); //delay the program for 1 second with the speaker off } // (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Watch the videos for line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!


Challenge

Can you complete the challenges? Check the box next to the challenge to 'mark it off' once it's complete!



These are the new code concepts covered in this example program. To become a great coder, read through these concepts to learn new vocabulary.

New Concept: Code doesn’t have a ‘default’ state

You may have noticed in this program that if you don’t turn the speaker off, it just keeps playing. This code concept is simple, but it causes confusion for some new programmers. The computer doesn’t ‘know’ that the speaker is playing too long, or that it’s getting annoying, or that it ‘should’ be off. The program just runs exactly as you write it. Keeping track of what is happening in your code takes some mental practice, but it’s also helpful to write code comments for yourself, which will help you catch simple mistakes like forgetting to turn off the speaker.


Quiz

If you're having trouble, try to run an experimental program or look at the example code to help you find the answer.

1. What are the arguments for the noTone function in this program?