# Programma 2 (drukknop + invoer samen mogelijk maken via thread)
import _thread
import settings
from machine import Pin
from time import sleep, ticks_ms
LED_PIN = 2
led_status = False
BUTTON_PIN = 26
button = Pin(BUTTON_PIN , Pin.IN, Pin.PULL_UP)
led = Pin(LED_PIN, Pin.OUT)
# bij het opstarten
button_before = 1
led.value(led_status)
flash_counter = settings.init_set()
# listen for terminal-commands
def wait_for_commands():
global flash_counter
while True:
command = input(">")
print("command was", command)
flash_counter = int(command)
settings.save_set(flash_counter)
_thread.start_new_thread(wait_for_commands, ())
while True:
button_now = button.value()
if button_now != button_before:
button_before = button_now
if button_now == 0:
for _ in range(flash_counter*2):
led_status = not led_status
sleep(0.5)
led.value(led_status)
settings.save_set(flash_counter)
sleep(0.005)
sleep(0.001) # voor thread