import machine
import time
# Define buzzer and LED pins
buzzerPin = machine.Pin(0, machine.Pin.OUT)
ledPin = machine.Pin(1, machine.Pin.OUT)
# Define Morse code patterns
dot = 0.25 # Dot duration in seconds
dash = 1.0 # Dash duration in seconds
gap = 0.2 # Gap duration in seconds
# Define SOS pattern
sosPattern = [".", "...", "-."]
# Function to flash the LED
def flashLED(duration):
ledPin.value(1)
time.sleep(duration)
ledPin.value(0)
# Function to sound the buzzer
def soundBuzzer(duration):
buzzerPin.value(1)
time.sleep(duration)
buzzerPin.value(0)
# Connect the LED to GPIO pin 1
ledPin = machine.Pin(1, machine.Pin.OUT)
# Connect the buzzer to GPIO pin 2
buzzerPin = machine.Pin(2, machine.Pin.OUT)
# Flash SOS signal
for symbol in sosPattern:
if symbol == ".":
flashLED(dot)
elif symbol == "-":
flashLED(dash)
else:
time.sleep(gap) # Wait between symbols
time.sleep(gap) # Wait between words
# Continuous beep
while True:
buzzerPin.value(1)
time.sleep(0.5)
buzzerPin.value(0)
time.sleep(0.5)