Piano Morse Code

Use Piano as a communications device, programming in a message to beep out in Morse code.

Code

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

/*Play a Morse Code message on the speaker Rules of Morse Code: - Dots are 1 'unit' of sound - Dashes are 3 'units' of sound (3 times as long as a dot) - Spaces between symbols within the same letter are 1 'unit' of silence - Spaces between letters are 3 'units' of silence - Spaces between words are 7 'units' of silence */ void setup(){ pinMode(10,OUTPUT); //Set the speaker as an 'OUTPUT' } void loop(){ //S //dot tone(10,500); //play a tone of 500 hertz on the speaker delay(300); //wait one 'dot' with the speaker on noTone(10); //turn off the sound delay(300); //wait before the next symbol in a letter //dot tone(10,500); //play a tone of 500 hertz on the speaker delay(300); //wait one 'dot' with speaker on noTone(10); //turn off the sound delay(300); //wait before the next symbol in a letter //dot tone(10,500); //play a tone of 500 hertz on the speaker delay(300); //wait one 'dot' with speaker on noTone(10); //turn off the sound delay(900); //wait before the next letter in a word //O //dash tone(10,500); //play a tone of 500 hertz delay(900); //wait one 'dash' with speaker on noTone(10); //turn off the sound delay(300); //wait before the next symbol in a letter //dash tone(10,500); //play a tone of 500 hertz delay(900); //wait one 'dash' with the speaker on noTone(10); //turn off the sound delay(300); //wait before the next symbol in a letter //dash tone(10,500); //play a tone of 500 hertz delay(900); //wait one 'dash' with speaker on noTone(10); //turn off the sound delay(900); //wait before the letter in a word //S //dot tone(10,500); //play a tone of 500 hertz on the speaker delay(300); //wait one 'dot' with the speaker on noTone(10); //turn off the sound delay(300); //wait before the next symbol in a letter //dot tone(10,500); //play a tone of 500 hertz on the speaker delay(300); //wait one 'dot' with the speaker on noTone(10); //turn off the sound delay(300); //wait before the next symbol in a letter //dot tone(10,500); //play a tone of 500 hertz on the speaker delay(300); //wait one 'dot' with the speaker on noTone(10); //turn off the sound delay(2100); //wait before the next word } // (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Walkthrough Videos

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!

Challenges

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


*International_Morse_Code.PNG

Concepts

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: Writing code for humans to read

When the computer reads your program, it doesn’t care about line breaks or comments. But in this program, you can imagine how confusing it would be to try and read or modify the code without comments breaking the Morse code message into letters and characters. Once you do that, it’s easy for a programmer like yourself to read through the code and figure out what is happening.

Practice updating your code comments when you’re writing programs. It will help you if you return to a program that you wrote in the past and it will help you clarify your thoughts about what you’re writing.

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. Which of the following affects how the computer reads your program?