from machine import Pin
from utime import sleep
led1_pin = Pin(13, Pin.OUT)
led2_pin = Pin(12, Pin.OUT)
led3_pin = Pin(14, Pin.OUT)
dp1_pin = Pin(2, Pin.IN)
dp2_pin = Pin(4, Pin.IN)
dp3_pin = Pin(16, Pin.IN)
#####################################
###### MAIN ROUTINE
def main():
while True:
sub_led1_off()
sub_led2_off()
sub_led3_off()
dp1_state = dp1_pin.value()
dp2_state = dp2_pin.value()
dp3_state = dp3_pin.value()
print(dp3_state,dp2_state,dp1_state)
# If DP1 is pushed AND DP2 is released
if dp1_state == 1 and dp2_state == 0 and dp3_state == 1 :
# then LED1 ON
sub_led1_on()
# then LED2 OFF
sub_led2_off()
# then LED3 OFF
sub_led3_off()
# If DP1 is released AND DP2 is pushed
elif dp1_state == 0 and dp2_state == 1 and dp3_state == 1:
# then LED1 ON
sub_led1_off()
# then LED2 OFF
sub_led2_on()
# then LED2 OFF
sub_led3_off()
# If DP1 & DP2 are pushed
elif dp1_state == 1 and dp2_state == 1 and dp3_state == 0:
# then LED1 ON
sub_led1_off()
# then LED2 OFF
sub_led2_off()
# then LED2 OFF
sub_led3_on()
# continue loop
#####################################
###### SUBROUTINE FOR LED
def sub_led1_on():
led1_pin.on()
sleep(0.5)
def sub_led1_off():
led1_pin.off()
sleep(0.5)
def sub_led2_on():
led2_pin.on()
sleep(0.5)
def sub_led2_off():
led2_pin.off()
sleep(0.5)
def sub_led3_on():
led3_pin.on()
sleep(0.5)
def sub_led3_off():
led3_pin.off()
sleep(0.5)
#####################################
###### EXECUTE MAIN ROUTINE
if __name__ == '__main__':
main()