BackBonus Project: Morse Code Transmitter
Difficulty
Optional — Extra Credit

What This Is
Hold the button briefly for a dot, hold it longer for a dash. Build up a letter, then let the board tell you which letter you sent.
You already know how to time a button press — that was Activity 2.7. The new part is deciding what a duration means, and then looking the answer up.

What You'll Need
- One button, from
3V3 with Pin.PULL_DOWN - The OLED, or just the terminal if you prefer
- Optional: the speaker, so you hear the dots and dashes as you send them

Build It
- Time a press. Start the clock when the button goes down, stop it when it comes up. Print the duration in milliseconds.
- Pick your cutoff. Press the button a lot of times, some short and some long, and look at the numbers. Choose a threshold that separates them for your thumb — nobody else can tell you what it is.
- Turn a press into a symbol. Below the cutoff is a dot, above it is a dash. Build up a string like
".-" as the presses come in. - Decide when a letter is finished. If nothing is pressed for a second or so, the letter is done.
- Look the letter up. Two lists that line up by position — one of Morse patterns, one of letters — exactly like Activity 1.23.
- Handle a pattern that is not in your list without crashing.
You do not need all 26 letters. Start with five you can test quickly — E is a single dot, T is a single dash, A is dot-dash, N is dash-dot, and S is three dots.

What Success Looks Like
. (120 ms)
- (410 ms)
letter: A
. (95 ms)
. (110 ms)
. (105 ms)
letter: S

Then Make It Yours
- Add the rest of the alphabet
- Collect letters into whole words, with a longer pause meaning a space
- Beep the dots and dashes as you send them
- Go the other way: type a letter and have the board flash it at you
Commence Project