from machine import Pin
from time import sleep
ledPinMerah = 33
ledPinHijau = 25
ledPinBiru = 26
ledPinKuning = 27
buttonMerah = Pin(4, Pin.IN, Pin.PULL_UP)
buttonHijau = Pin(2, Pin.IN, Pin.PULL_UP)
buttonBiru = Pin(0, Pin.IN, Pin.PULL_UP)
buttonKuning = Pin(15, Pin.IN, Pin.PULL_UP)
buttonAll = Pin(16, Pin.IN, Pin.PULL_UP)
ledMerah = Pin(ledPinMerah, Pin.OUT)
ledHijau = Pin(ledPinHijau, Pin.OUT)
ledBiru = Pin(ledPinBiru, Pin.OUT)
ledKuning = Pin(ledPinKuning, Pin.OUT)
stateMerah = 1
stateHijau = 1
stateBiru = 1
stateKuning = 1
stateAll = 1
while True:
if buttonMerah.value() != stateMerah:
if buttonMerah.value() == 0:
ledMerah.on()
print("lampu merah nyala")
elif buttonMerah.value() == 1:
ledMerah.off()
print("lampu merah mati")
stateMerah = buttonMerah.value()
sleep(0.1)
if buttonHijau.value() != stateHijau:
if buttonHijau.value() == 0:
ledHijau.on()
print("lampu hijau nyala")
elif buttonHijau.value() == 1:
ledHijau.off()
print("lampu hijau mati")
stateHijau = buttonHijau.value()
sleep(0.1)
if buttonBiru.value() != stateBiru:
if buttonBiru.value() == 0:
ledBiru.on()
print("lampu biru nyala")
elif buttonBiru.value() == 1:
ledBiru.off()
print("lampu biru mati")
stateBiru = buttonBiru.value()
sleep(0.1)
if buttonKuning.value() != stateBiru:
if buttonKuning.value() == 0:
ledKuning.on()
print("lampu kuning nyala")
elif buttonKuning.value() == 1:
ledKuning.off()
print("lampu kuning mati")
stateKuning = buttonKuning.value()
sleep(0.1)
if buttonAll.value() != stateAll:
if buttonAll.value() == 0:
ledMerah.on()
ledHijau.on()
ledBiru.on()
ledKuning.on()
print("semua lampu nyala")