Skip to content

Instantly share code, notes, and snippets.

@Leowbattle
Created April 7, 2024 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leowbattle/1d3434e452382df6b31116c670b3e1c0 to your computer and use it in GitHub Desktop.
Save Leowbattle/1d3434e452382df6b31116c670b3e1c0 to your computer and use it in GitHub Desktop.
Morse code transmitter for Raspberry Pi Pico
from machine import Pin
import utime
buzzer = Pin(16, Pin.OUT)
dit_time = 0.05
dah_time = dit_time * 3
message = "SOS WE ARE SINKING"
morse_code = {
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---',
'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-',
'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--', 'Z': '--..',
'0': '-----', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....',
'6': '-....', '7': '--...', '8': '---..', '9': '----.',
}
for c in message:
if c == ' ':
utime.sleep(dit_time * 7)
continue
code = morse_code[c]
for x in code:
buzzer(1)
if x == '.':
utime.sleep(dit_time)
elif x == '-':
utime.sleep(dah_time)
buzzer(0)
utime.sleep(dit_time * 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment