from machine import Pin, PWM
from time import sleep
import time
servo = PWM(Pin(0))
servo.freq(50)
# Define the GPIO pins for the red and blue LEDs, and toggle switch
red_led_pin = Pin(18, Pin.OUT) # GPIO pin for the red LED
blue_led_pin = Pin(19, Pin.OUT) # GPIO pin for the blue LED
switch_pin = Pin(27, Pin.IN, Pin.PULL_UP) # GPIO pin for the toggle switch
# Initialize variables
led_state = False
switch_state = switch_pin.value()
counter = 0
# Function to update LED state based on switch state
def update_led_state():
global led_state
led_state = switch_pin.value()
red_led_pin.value(led_state)
# Main loop
while True:
# Check the state of the toggle switch
new_switch_state = switch_pin.value()
# If the switch state has changed, update the LED state accordingly
if switch_state != new_switch_state:
update_led_state()
servo.duty_u16(1500)
sleep(0.2)
# If the switch is turned on, increment the counter
if led_state:
counter += 1
print("LED switched on. Count:", counter)
servo.duty_u16(8100)
sleep(0.2)
# If the counter reaches 5, activate the blue LED and disable red LED switching
if counter == 5:
blue_led_pin.value(1)
print("Blue LED activated!")
red_led_pin.value(0) # Turn off the red LED
# Update the switch state
switch_state = new_switch_state
# Add a short delay to debounce the switch
time.sleep(0.1)
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
sw1:1
sw1:2
sw1:3
r1:1
r1:2
r2:1
r2:2
led1:A
led1:C
led2:A
led2:C
servo1:GND
servo1:V+
servo1:PWM