import time
import board
import digitalio
switch = digitalio.DigitalInOut(board.GP17)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.DOWN
poorten = [board.GP18, board.GP19, board.GP20, board.GP21]
leds = [digitalio.DigitalInOut(poort) for poort in poorten]
for led in leds:
led.direction = digitalio.Direction.OUTPUT
knopIngedrukt = False
teller = 0
tijdStart = 0
while True:
while switch.value == True:
knopIngedrukt = True
time.sleep(0.2)
print("knop ingedrukt")
if tijdStart == 0:
tijdStart = time.monotonic()
if switch.value == False and knopIngedrukt == True:
teller +=1
knopIngedrukt = False
if tijdStart != 0 and time.monotonic() - tijdStart >= 2:
print("aantal keer knop ingedruk:", teller)
for x in range(min(teller, len(leds))):
leds[x].value = True
time.sleep(0.5)
leds[x].value = False
time.sleep(0.5)
teller = 0
tijdStart = 0