Speaker Morse Code: Part Two Bug Hunt! Test your Troubleshooting.
This code won’t upload to your Speaker. Can you find the error before you even press ‘Upload’ ?
/*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
*/
int dit = 200; //milliseconds that a dot will last
int dash = dot*3; //milliseconds that a dash will last
int symbol = dot; // space between symbols are the same duration as a dot
int letter = symbol*3; //space between letters are 3 times the duration of symbol spaces
int wordSpace = symbol*7; //space between words are 7 times the duration of symbol spaces
int pitch = 500; //the hertz value that will be used for your tones
void setup(){
pinMode(10,OUTPUT); //Set Speaker as an 'OUTPUT'
}
void loop(){
//S
tone(10,pitch); //Play a tone of 'pitch' on the speaker
delay(dot); //wait one 'dot' with tone playing
noTone(10);
delay(symbol); //wait before the next symbol in a letter
tone(10,pitch); //Play a tone of 'pitch' on the speaker
delay(dot); //wait one 'dot' with tone playing
noTone(10);
delay(symbol); //wait before the next symbol in a letter
tone(10,pitch); //Play a tone of 'pitch' on the speaker
delay(dot); //wait one 'dot' with tone playing
noTone(10);
delay(letter); //wait before the next symbol in a letter
//O
tone(10,pitch); //Play a tone of 'pitch' on the speaker
delay(dash); //wait one 'dot' with tone playing
noTone(10);
delay(symbol); //wait before the next symbol in a letter
tone(10,pitch); //Play a tone of 'pitch' on the speaker
delay(dash); //wait one 'dot' with tone playing
noTone(10);
delay(symbol); //wait before the next symbol in a letter
tone(10,pitch); //Play a tone of 'pitch' on the speaker
delay(dash); //wait one 'dot' with tone playing
noTone(10);
delay(letter); //wait before the next symbol in a letter
//S
tone(10,pitch); //Play a tone of 'pitch' on the speaker
delay(dot); //wait one 'dot' with tone playing
noTone(10);
delay(symbol); //wait before the next symbol in a letter
tone(10,pitch); //Play a tone of 'pitch' on the speaker
delay(dot); //wait one 'dot' with tone playing
noTone(10);
delay(symbol); //wait before the next symbol in a letter
tone(10,pitch); //Play a tone of 'pitch' on the speaker
delay(dot); //wait one 'dot' with tone playing
noTone(10);
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 a bug at the top of a program can cause the computer to see lots of errors throughout the code. Don't be overwhelmed! Use the errors as clues and see what they have in common.
Look at the spelling of each variable that is used throughout the program. One of them is misspelled when it's created above the void seutp(). After that, every time the code references 'dot', it can't find a variable with that name.