pizzabox-ctrl/micropizza/test.py

25 lines
No EOL
665 B
Python

from machine import Pin, Timer
import time
led = Pin(25, Pin.OUT)
btn_blu = Pin(2, Pin.IN, Pin.PULL_UP)
btn_red = Pin(3, Pin.IN, Pin.PULL_UP)
def user_interaction(timeout):
def _toggle_leds(timer):
led.toggle()
tmr = Timer()
tmr.init(freq=2, mode=Timer.PERIODIC, callback=_toggle_leds)
startime = time.ticks_ms()
timeout *= 1000
while time.ticks_diff(time.ticks_ms(), startime) < timeout:
b, r = btn_blu.value(), btn_red.value()
if (b + r) < 2:
tmr.deinit()
return 'B' if not b else 'R'
tmr.deinit()
return 'T' # Timeout
if __name__ == '__main__':
print(user_interaction(20))