import machine
import time
# Set up GPIO pins
LED_PINS = [4, 5, 12, 13] # Define GPIO pins for LEDs
BUTTON_PIN = 14
BUZZER_PIN = 23
# Configure GPIO pins
led_pins = [machine.Pin(pin, machine.Pin.OUT) for pin in LED_PINS]
button_pin = machine.Pin(BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_UP)
buzzer_pin = machine.Pin(BUZZER_PIN, machine.Pin.OUT)
# Function to turn on LED
def turn_on_led(led_pin):
led_pin.on()
# Function to turn off LED
def turn_off_led(led_pin):
led_pin.off()
# Function to turn on buzzer
def turn_on_buzzer():
buzzer_pin.on()
# Function to turn off buzzer
def turn_off_buzzer():
buzzer_pin.off()
while True:
# Get input for LED
led_input = int(input("Enter the LED number (1-4): "))
# Turn on LED
turn_on_led(led_pins[led_input - 1])
# Wait for pushbutton press
while button_pin.value() == 1:
pass
# Turn off LED
turn_off_led(led_pins[led_input - 1])
# Get input for buzzer time
buzzer_time = int(input("Enter the time for buzzer (seconds): "))
# Start buzzer
turn_on_buzzer()
# Wait for specified time
time.sleep(buzzer_time)
# Check if pushbutton is pressed
if button_pin.value() == 0:
# Turn off buzzer
turn_off_buzzer()
else:
# Print emergency contact message
print("Emergency Contact: Push button not pressed in time.")