Lesson 15: Morse code beacon
Messages in light and sound
- Before radios could carry voices, ships and soldiers sent messages in Morse code: short and long signals.
- A short signal is a dot (·), a long one is a dash (—). Each letter has its own pattern.
- SOS (· · · — — — · · ·) means "help!". It is easy to send and easy to hear.
Words for this lesson
| Word | Meaning |
|---|---|
| beacon | a light or sound that sends a signal far away |
| dot / dash | a short / a long signal |
| function | a named group of lines you can call again and again |
| string | text, like ".-" |
| gap | a short time with no signal |
The timing rules
- Everything is built from one unit of time. Here a unit is 200 ms.
| Part | Length | In this sketch |
|---|---|---|
| dot | 1 unit | on 200 ms |
| dash | 3 units | on 600 ms |
| gap inside a letter | 1 unit | off 200 ms (at the end of dot() and dash()) |
| gap between letters | 3 units | 200 + delay(400) = 600 ms |
| gap between words | 7 units | 200 + delay(1400) = 1600 ms |
Some letters
| A | E | I | M | N | O | S | T |
|---|---|---|---|---|---|---|---|
| · — | · | · · | — — | — · | — — — | · · · | — |
Functions save typing
void dot() {
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
}
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
dot();
dot();
delay(1400);
}
void dot() { ... }makes the function.dot();calls it: the board runs its lines, then comes back.- This sketch sends I (· ·) again and again. With
tone(8, 600)andnoTone(8)a buzzer on pin 8 beeps at the same time.
רמת קושי 3/5 · 200 מטבעות + בונוס קטן בהשלמה הראשונה היום
Send SOS (· · · — — — · · ·) with the LED on pin 13 and a beep on the buzzer on pin 8. dot() is done. Write dash(): on for 600 ms, then off for 200 ms. Then call them in loop(): three dots, three dashes, three dots, with delay(400) after each letter, and delay(1400) at the end.
לחץ על הרץ כדי לראות את התוצא כאן.
רמת קושי 4/5 · 280 מטבעות + בונוס קטן בהשלמה הראשונה היום
Make a beacon that sends any word you type in the Serial Monitor. code() gives the Morse code of a letter as a string, like ".-" for A. Finish send(): go through the string with a for loop; for each . קריאה dot(), for each - קריאה dash(). Try it: type SOS, then your name.
לחץ על הרץ כדי לראות את התוצא כאן.