from machine import Pin
from time import sleep
leds = [Pin(pin, Pin.OUT) for pin in [21, 19, 18, 5, 4, 2, 15, 22]]
button = Pin(12, Pin.IN, Pin.PULL_UP)
current_mode = 0
previous_button_state = 1
def blink_all_leds():
print("Chế độ 1: Nhấp nháy tất cả LED")
for led in leds:
led.on()
sleep(0.5)
for led in leds:
led.off()
sleep(0.5)
def light_up_sequentially():
print("Chế độ 2: Bật LED theo thứ tự")
for led in leds:
led.on()
sleep(0.1)
led.off()
for led in reversed(leds):
led.on()
sleep(0.1)
led.off()
while True:
current_button_state = button.value()
if previous_button_state == 1 and current_button_state == 0:
current_mode += 1
if current_mode > 1:
current_mode = 0
print(f"Chế độ hiện tại: {current_mode}")
previous_button_state = current_button_state
if current_mode == 0:
blink_all_leds()
else:
light_up_sequentially()
sleep(0.1)