Created
April 7, 2024 15:03
-
-
Save Leowbattle/1d3434e452382df6b31116c670b3e1c0 to your computer and use it in GitHub Desktop.
Morse code transmitter for Raspberry Pi Pico
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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