Rocket Morse Code Part Three Bug Hunt! Test your Troubleshooting.
This code has the same sort of error, repeated 4 times throughout. See if you can hunt it down without pressing “Upload”. It’s a sneaky one!
/*Buggy: 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
noTnoe(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
noTnoe(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
tnoe(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
noTnoe(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
Heads up! You need our Chrome App to run this code.
Success!
Compile errors:
Serial port monitor:
Input: