import time
from machine import Pin
LED_PINS = [0,4,9,15]
On_button = (20, Pin.IN)
Off_button = (28,Pin.IN)
led_state = "OFF"
blinking = False
def turn_on_leds():
"""Turn on all LEDs."""
for pin in LED_PINS:
print(f"{pin} is ON")
print("All LEDs are ON")
global led_state
led_state = "ON"
def turn_off_leds():
"""Turn off all LEDs."""
for pin in LED_PINS:
print(f"{pin} is OFF")
print("All LEDs are OFF")
global led_state
led_state = "OFF"
def blink_leds():
"""Blink LEDs in sequence."""
global blinking
while blinking:
for pin in LED_PINS:
print(f"{pin} is ON")
time.sleep(0.5)
print(f"{pin} is OFF")
time.sleep(0.5)
def button_callback():
"""Handle button press events."""
global led_state, blinking
if led_state == "OFF":
turn_on_leds()
elif led_state == "ON":
blinking = True
print("LEDs will now blink in sequence.")
led_state = "BLINK"
elif led_state == "BLINK":
blinking = False
turn_off_leds()
try:
print("Press the button to control the LEDs.")
while True:
button_pressed = False
button_callback()
time.sleep(0.1)
except KeyboardInterrupt:
print("Program stopped by User")
finally:
turn_off_leds()