from machine import Pin, PWM
from utime import sleep
# Define LEDs
red = Pin(5, Pin.OUT)
yellow = Pin(4, Pin.OUT)
green = Pin(3, Pin.OUT)
# Define Servo Motor on GPIO 2
servo = PWM(Pin(2))
servo.freq(50) # Set PWM frequency to 50Hz
# Function to set servo angle
def set_servo_angle(angle):
duty = int((angle / 180) * 5000 + 1000) # Convert angle to duty cycle (1000-8000)
servo.duty_u16(duty)
# Function to make the buzzer beep
def beep(duration):
sleep(duration)
sleep(0.2)
while True:
# Red Light ON (Servo Closed) - Long Buzzer Beep
red.value(1)
yellow.value(0)
green.value(0)
set_servo_angle(0) # Close the servo
print("RED Light ON - Servo Closed")
sleep(1)
# Yellow Light ON - Short Buzzer Beep
red.value(0)
yellow.value(1)
green.value(0)
print("YELLOW Light ON")
sleep(1)
# Green Light ON (Servo Open) - No Buzzer
red.value(0)
yellow.value(0)
green.value(1)
set_servo_angle(90) # Open the servo
print("GREEN Light ON - Servo Open")
sleep(3)
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C
servo1:GND
servo1:V+
servo1:PWM