import time
import board
import digitalio
import pwmio
# ==========================================
# INITIALIZE INPUTS AND OUTPUTS
# ==========================================
# --- Outputs ---
led_green = digitalio.DigitalInOut(board.GP10)
led_green.direction = digitalio.Direction.OUTPUT
led_red = digitalio.DigitalInOut(board.GP11)
led_red.direction = digitalio.Direction.OUTPUT
led_yellow = digitalio.DigitalInOut(board.GP12)
led_yellow.direction = digitalio.Direction.OUTPUT
# Buzzer (Using PWM for variable frequencies)
buzzer = pwmio.PWMOut(board.GP16, frequency=1000, duty_cycle=0, variable_frequency=True)
# --- Inputs ---
# Push Button 1 (Arm System)
btn_1 = digitalio.DigitalInOut(board.GP15)
btn_1.direction = digitalio.Direction.INPUT
btn_1.pull = digitalio.Pull.DOWN
# Helper functions to easily control the buzzer
def play_buzzer(freq, duration=None):
buzzer.frequency = freq
buzzer.duty_cycle = 32768 # Set volume to 50%
if duration is not None:
time.sleep(duration)
buzzer.duty_cycle = 0 # Turn off after duration
def stop_buzzer():
buzzer.duty_cycle = 0
# ==========================================
# PART 1: ARMING
# ==========================================
while True:
# Check the Push Button 1
if btn_1.value: # Push Button 1 Pressed? (Yes)
# Activate the Alarm System by Sounding the Buzzer
play_buzzer(1000, 0.2)
# Turn ON Green LED
led_green.value = True
time.sleep(0.2) # Debounce delay
break # Move to the main monitoring loop