from machine import Pin
import time
btn_in = Pin(32, Pin.IN)
btn_out = Pin(35, Pin.IN)
led1 = Pin(22, Pin.OUT)
led2 = Pin(21, Pin.OUT)
led3 = Pin(19, Pin.OUT)
led4 = Pin(18, Pin.OUT)
led5 = Pin(5, Pin.OUT)
led6 = Pin(17, Pin.OUT)
led7 = Pin(4, Pin.OUT)
led8 = Pin(2, Pin.OUT)
leds = [led1, led2, led3, led4, led5, led6, led7, led8]
for led in leds:
led.value(0)
x = 0
prev_in = 0
prev_out = 0
while True:
current_in = btn_in.value()
current_out = btn_out.value()
if current_in == 1 and prev_in == 0:
if x < len(leds):
leds[x].value(1)
x += 1
print("number of car",x)
else:
print("All LEDs are already ON")
time.sleep(0.2)
if current_out == 1 and prev_out == 0:
if x > 0:
x -= 1
leds[x].value(0)
print("number of car",x)
else:
print("All LEDs are already OFF")
time.sleep(0.2)
prev_in = current_in
prev_out = current_out