from machine import Pin
import time
# Define GPIO pins
led1_pin = Pin(2, Pin.OUT)
led2_pin = Pin(16, Pin.OUT)
dp1_pin = Pin(35, Pin.IN)
dp2_pin = Pin(34, Pin.IN)
# Main loop
while True:
# initial state ( NAK BAGI LED TU MAINTAIN OFF TANPA BUAT APE APE )
led1_pin.off()
led2_pin.off()
# Read the state of the switch
dp1_state = dp1_pin.value()
dp2_state = dp2_pin.value()
# If the dp switch 1 is ON, LED 1 ON LED 2 OFF
# Elif the dp switch 1 is OFF, LED 1 OFF LED 2 OFF
if dp1_state == True:
led1_pin.on()
led2_pin.off()
elif dp1_state == False:
led1_pin.off()
led2_pin.off()
# If the dp switch 2 is ON, LED 1 OFF LED 2 ON
# Elif the dp switch 2 is OFF, LED 1 OFF LED 2 OFF
if dp2_state == True:
led1_pin.off()
led2_pin.on()
elif dp2_state == False:
led1_pin.off()
led2_pin.off()
# Delay for a short period
time.sleep(0.1)