from machine import Pin, Timer
import time
# Set up the LED pins
device_on_led = Pin(0, Pin.OUT) # Assuming Pin 0 is correct for device_on_led
led = Pin(5, Pin.OUT) # Assuming Pin 5 is correct for led
button_1 = Pin(7, Pin.IN, Pin.PULL_UP)
button_2 = Pin(11, Pin.IN, Pin.PULL_UP)
timer = Timer()
blink = False
def blink_led():
blink = not blink
timer.init(0.5, mode=Timer.PERIODIC, callback=blink_led)
# Main loop
def main():
state = "off"
end_time = 0
while True:
device_on_led.on()
if button_1.value() == 0:
if state == "off":
state = "on"
else:
state = "off"
time.sleep(0.2) # Simple debounce
if button_2.value() == 0:
if state == "on":
end_time = time.time() + 10
state = "blink"
elif state == "blink":
state = "on"
time.sleep(0.2)
if time.time() > end_time and state == "blink":
state = "on"
if state == "off":
led.off()
elif state == "on":
led.on()
elif state == "blink":
if blink:
led.on()
else:
led.off()
time.sleep(0.01) # Small delay to debounce the buttons
# Entry point of the script
if __name__ == "__main__":
main()