from machine import Pin
import time
# Daftar mapping tombol ke LED
button_led_map = {
2: [6, 7], # button_1 mengontrol led_1 dan led_2
3: [8, 10], # button_2 mengontrol led_2 dan led_3
4: [11, 12], # button_3 mengontrol led_3 dan led_4
}
# Inisialisasi LED sebagai output
leds = {pin: Pin(pin, Pin.OUT) for pin in {6, 7, 8, 10, 11, 12}}
# Inisialisasi push button sebagai input dengan pull-down
buttons = {pin: Pin(pin, Pin.IN, Pin.PULL_DOWN) for pin in button_led_map.keys()}
while True:
for button_pin, led_pins in button_led_map.items():
if buttons[button_pin].value() == 1:
for led_pin in led_pins:
leds[led_pin].on()
else:
for led_pin in led_pins:
leds[led_pin].off()
time.sleep(0.05) # Delay untuk debounce sederhana