from machine import Pin, Timer
import time
led_pin = Pin(13, Pin.OUT) # Change the pin number according to your setup
dot_duration = 0.25
dash_duration = 1
gap_duration = 0.5
repeat_delay = 2
morse_code = "...---..."
def transmit_morse_code():
for symbol in morse_code:
if symbol == '.':
led_pin.on()
time.sleep(dot_duration)
elif symbol == '-':
led_pin.on()
time.sleep(dash_duration)
else:
# Symbol is a space (GAP)
led_pin.off()
time.sleep(gap_duration)
led_pin.off()
time.sleep(gap_duration)
time.sleep(repeat_delay)
# Set up a timer to repeatedly transmit the Morse code
timer = Timer()
def on_timer(timer):
transmit_morse_code()
timer.init(freq=1/2, mode=Timer.PERIODIC, callback=on_timer)
# Run the program indefinitely
while True:
pass