Rocket Morse Code Part Four Bug Hunt! Test your Troubleshooting.
You may have already run into some errors in modifying or writing your own code. Don't worry, studies have shown that almost half of all code 'compiles' result in an error!
Don’t be scared by the number of errors that show up when you try to upload this program. There is a single, simple solution!
/*Buggy: Use variables for Morse Code messages. This will make it much easier to update
the speed of messages
Rules of Morse Code:
- Dots are 1 'unit'
- Dashes are 3 'units' (3 times as long as a dot)
- Spaces between symbols within the same letter are 1 'unit' of no signal
- Spaces between letters are 3 'units' of no signal
- Spaces between words are 7 'units' of no signal
*/
//all the variables used in this program are 'integers', shortened to int, which means they are whole numbers.
int dit = 200; //milliseconds that a dot will last
int dash = dot*3; //milliseconds that a dash will last
int symbolSpace = dot; // space between symbols are the same duration as a dot
int letterSpace = symbolSpace*3; //space between letters are 3 times the duration of symbol spaces
int wordSpace = symbolSpace*7; //space between words are 7 times the duration of symbol spaces
int LED = 6;
void setup(){
pinMode(LED,OUTPUT); //Set the LED as an 'OUTPUT'
}
void loop(){
//S
digitalWrite(LED,HIGH); //Turn on LED
delay(dot); //wait one 'dot' with LED on
digitalWrite(LED,LOW); //Turn off LED
delay(symbolSpace); //wait before the next symbol in a letter
digitalWrite(LED,HIGH); //Turn on LED
delay(dot); //wait one 'dot' with LED on
digitalWrite(LED,LOW); //Turn off LED
delay(symbolSpace); //wait before the next symbol in a letter
digitalWrite(LED,HIGH); //Turn on LED
delay(dot); //wait one 'dot' with LED on
digitalWrite(LED,LOW); //Turn off LED
delay(letterSpace); //wait before the next symbol in a letter
//O
digitalWrite(LED,HIGH); //Turn on LED
delay(dash); //wait one 'dash' with LED on
digitalWrite(LED,LOW); //Turn off LED
delay(symbolSpace); //wait before the next symbol in a letter
digitalWrite(LED,HIGH); //Turn on LED
delay(dash); //wait one 'dash' with LED on
digitalWrite(LED,LOW); //Turn off LED
delay(symbolSpace); //wait before the next symbol in a letter
digitalWrite(LED,HIGH); //Turn on LED
delay(dash); //wait one 'dash' with LED on
digitalWrite(LED,LOW); //Turn off LED
delay(letterSpace); //wait before the next letter in a word
//S
digitalWrite(LED,HIGH); //Turn on LED
delay(dot); //wait one 'dot' with LED on
digitalWrite(LED,LOW); //Turn off LED
delay(symbolSpace); //wait before the next symbol in a letter
digitalWrite(LED,HIGH); //Turn on LED
delay(dot); //wait one 'dot' with LED on
digitalWrite(LED,LOW); //Turn off LED
delay(symbolSpace); //wait before the next symbol in a letter
digitalWrite(LED,HIGH); //Turn on LED
delay(dot); //wait one 'dot' with LED on
digitalWrite(LED,LOW); //Turn off LED
delay(wordSpace); //wait before the next word
}
// (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
Heads up! You need our Chrome App to run this code.
Success!
Compile errors:
Serial port monitor:
Input:
Need a hint? Click here.
Sometimes an error near the top of the program can cause a bunch of errors to arise throughout the code. Before you start trying to 'zoom in' and fix each error, try to see what they all have in common. In this case, it has to do with one of your variable names being misspelled.