Piano Morse code Bug Hunt! Test your Troubleshooting.
This code will upload to Code Piano, but it won’t run as you expect it to. Can you find out what’s causing the problem?
/*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
Heads up! You need our Chrome App to run this code.
Success!
Compile errors:
Serial port monitor:
Input:
Need a hint? Click here.
'Commenting out' a piece of code means to add two slashes in front of that line of code. When you do that, the code turns into a comment, so it's not deleted, but the computer ignores that code. It's a useful tool when you're experimenting with code, but in this bug hunt there is a line of code that is 'commented out' accidentally.
Find the accidental comment and delete the two slashes so that the line of code is read by the computer when you upload it.