Start combining LED blinks into something useful - a message asking for help in case the astronauts on Code Rocket get into trouble!

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.

/*Flash out a Morse Code message on an LED light 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' } void loop(){ //S //dot digitalWrite(6,HIGH); //Turn on LED 6 delay(300); //wait one 'dot' with LED on digitalWrite(6,LOW); //Turn off LED 6 delay(300); //wait before the next symbol in a letter //dot digitalWrite(6,HIGH); //Turn on LED 6 delay(300); //wait one 'dot' with LED on digitalWrite(6,LOW); //Turn off LED 6 delay(300); //wait before the next symbol in a letter //dot digitalWrite(6,HIGH); //Turn on LED 6 delay(300); //wait one 'dot' with LED on digitalWrite(6,LOW); //Turn off LED 6 delay(900); //wait before the next letter in a word //O //dash digitalWrite(6,HIGH); //Turn on LED 6 delay(900); //wait one 'dash' with LED on digitalWrite(6,LOW); //Turn off LED 6 delay(300); //wait before the next symbol in a letter //dash digitalWrite(6,HIGH); //Turn on LED 6 delay(900); //wait one 'dash' with LED on digitalWrite(6,LOW); //Turn off LED 6 delay(300); //wait before the next symbol in a letter //dash digitalWrite(6,HIGH); //Turn on LED 6 delay(900); //wait one 'dash' with LED on digitalWrite(6,LOW); //Turn off LED 6 delay(900); //wait before the next letter in a word //S //dot digitalWrite(6,HIGH); //Turn on LED 6 delay(300); //wait one 'dot' with LED on digitalWrite(6,LOW); //Turn off LED 6 delay(300); //wait before the next symbol in a letter //dot digitalWrite(6,HIGH); //Turn on LED 6 delay(300); //wait one 'dot' with LED on digitalWrite(6,LOW); //Turn off LED 6 delay(300); //wait before the next symbol in a letter //dot digitalWrite(6,HIGH); //Turn on LED 6 delay(300); //wait one 'dot' with LED on digitalWrite(6,LOW); //Turn off LED 6 delay(2100); //wait before the next word in a message } // (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!


*International_Morse_Code.PNG

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: Complexity and organization

This example program uses simple concepts you’ve seen before, but it’s a much longer program! Don’t get overwhelmed by the number of lines of code; try to break down the concepts into pieces and understand each piece. Once you understand the pieces, it’s easier to ‘zoom out’ and look at the program as a whole.

Notice the use of comments and line breaks throughout this program. Remember that the computer doesn’t need line breaks, blank lines, or comments for the program to work - those are tools for humans. When you are tinkering with code, remember to leave yourself notes and comments so the code is overwhelming if you come back to it later.


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?