from machine import Pin, Timer
# import time
# Configure a pin for LED control
LED = Pin(0, Pin.OUT)
# This configures the pin that the switch is
# connected to
# Note: the PULL_UP resister is enabled so we can detect the pin voltage
SWITCH = Pin(2, Pin.IN, Pin.PULL_UP)
# This function just toggles the LED on/off
# def flash_led(my_timer):
# LED.toggle()
# This function will be called by 'switch_timer to check if the
# the switch (Pico:GP2) is on or off
# Note:
def check_switch(switch_timer):
print(SWITCH.value())
# check if the value of Pico:GP2 is on and of so toggle the LED
if SWITCH.value() == 1:
LED.toggle()
# If it is not on simply shut the LED off
else:
LED.off()
# Set a timer that calls the 'flash_led' function every 1 second
# Note: Timer 'period' is in milliseconds
# Note: Timer.PERIODIC means contiue to run until stopped
# my_timer = Timer(mode=Timer.PERIODIC, period=1000, callback=flash_led)
# This time works just like the LED flasher buy it is being used to trigger
# the function that checks if the switch is currently on or off
switch_timer = Timer(mode=Timer.PERIODIC, period=1000, callback=check_switch)