Take your horn beeps to the next level with more tones and tunes! Beep the horn on Code Car automatically in song sequences.
The code below already works and is ready to upload! Upload the code to Code Car and see what happens. Then, you'll 'take apart' the code to learn what each piece of the program does.
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!
How many can you complete? Change the code according to the challenges below. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!
Use the internet to find a table that converts hertz to musical notes. Can you make some of the following songs?
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: Repetition and Patterns (Again)
The challenges on this lesson are very open-ended, and they can get long. Some students have written hundreds of lines of code to create their favorite song from a movie or video game. Most songs, like most code, is made up of patterns that repeat or at least use the same tools (notes and pauses, for example) to create something unique. So while it may seem intimidating to look at a huge block of code, remember to try to pick out the patterns and deconstruct the program into its pieces.
New Concept: Styling
The longer your programs become, the more important styling becomes. There is more than one way to style code, but your goal should be to make your code readable to yourself and to anyone else who reads it. Looking at the coding example above, you can see that everything inside the void loop() is indented one line. That's not so the computer can read it, it's so programmers can easily see where the loop ends (it's the closing curly brace that's not indented). Also notice the blank lines between each tone+delay pair. That doesn't affect how the code runs, but it breaks the program into 'notes' and 'rests' that are easier for humans to read.