Rocket Morse Code: Part Three

Use all of the tools at your disposal to send a Morse code SOS message with lights and sounds. When times get desperate in deep space, you want any possible audience to receive your message!

Code

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.

/*Play a Morse Code message on the speaker AND LEDs 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(6,OUTPUT); //Set the LED as an 'OUTPUT' pinMode(2,OUTPUT); //Set the speaker as an 'OUTPUT' } void loop(){ //S digitalWrite(6,HIGH); //turn on the LED tone(2,500); //play a tone of 500 hertz on the speaker (2) delay(300); //wait one 'dot' with LED on noTone(2); //turn off the sound digitalWrite(6,LOW); //turn off the LED delay(300); //wait before the next symbol in a letter digitalWrite(6,HIGH); //turn on the LED tone(2,500); //play a tone of 500 hertz on the speaker (2) delay(300); //wait one 'dot' with LED on noTone(2); //turn off the sound digitalWrite(6,LOW); //turn off the LED delay(300); //wait before the next symbol in a letter digitalWrite(6,HIGH); //turn on the LED tone(2,500); //play a tone of 500 hertz on the speaker (2) delay(300); //wait one 'dot' with LED on noTone(2); //turn off the sound digitalWrite(6,LOW); //turn off the LED delay(900); //wait before the next symbol in a letter //O digitalWrite(6,HIGH); //turn on the LED tone(2,500); //play a tone of 500 hertz delay(900); //wait one 'dash' with LED on digitalWrite(6,LOW); //turn off the LED noTone(2); //turn off the sound delay(300); //wait before the next symbol in a letter digitalWrite(6,HIGH); //turn on the LED tone(2,500); //play a tone of 500 hertz delay(900); //wait one 'dash' with LED on digitalWrite(6,LOW); //turn off the LED noTone(2); //turn off the sound delay(300); //wait before the next symbol in a letter digitalWrite(6,HIGH); //turn on the LED tone(2,500); //play a tone of 500 hertz delay(900); //wait one 'dash' with LED on digitalWrite(6,LOW); //turn off the LED noTone(2); //turn off the sound delay(900); //wait before the next symbol in a letter //S digitalWrite(6,HIGH); //turn on the LED tone(2,500); //play a tone of 500 hertz on the speaker (2) delay(300); //wait one 'dot' with LED on noTone(2); //turn off the sound digitalWrite(6,LOW); //turn off the LED delay(300); //wait before the next symbol in a letter digitalWrite(6,HIGH); //turn on the LED tone(2,500); //play a tone of 500 hertz on the speaker (2) delay(300); //wait one 'dot' with LED on noTone(2); //turn off the sound digitalWrite(6,LOW); //turn off the LED delay(300); //wait before the next symbol in a letter digitalWrite(6,HIGH); //turn on the LED tone(2,500); //play a tone of 500 hertz on the speaker (2) delay(300); //wait one 'dot' with LED on noTone(2); //turn off the sound digitalWrite(6,LOW); //turn off the LED delay(2100); //wait before the next word in a message } // (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? Change the code in the editor above, then upload it to your Code Rocket and see if you got the result. Don't stop here, keep experimenting with the code!


*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: Speed, revisited

You’ve already experienced the power of speed in your programs. Here, you can see how a program can allow you to basically do two things at once: play your message on the speaker and the LED light at one time. If you do the challenge, you’ll see that as long as you don’t add any extra delays to the program, you can add in more functionality and make the program still look like everything is happening at the same time.

New Concept: Combining programs

Combining programs is not always an easy task. With so many details like where the curly braces go, ensuring you don’t delete a semicolon, and keeping the logic straight, there is much more to combining two programs than simply ‘copy, paste’. If you want to combine programs, it’s recommended that you upload the partially completed project a few times to Code Rocket to ensure you’re not creating errors that will overwhelm you later. It’s no fun to try an upload and find 50 errors!

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. How many code commands can be added to a program before it freezes?