-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnor_latch.py
33 lines (26 loc) · 862 Bytes
/
nor_latch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import time
from machine import Pin
# The LED is the output, the buttons are inputs.
led = Pin(2, Pin.OUT)
button_on = Pin(12, Pin.IN, Pin.PULL_UP)
button_off = Pin(14, Pin.IN, Pin.PULL_UP)
def wait_for_button(pin, reversed = False):
while True:
time.sleep_ms(20)
print(pin.value())
# Every 20 ms, check if the button is pressed.
if pin.value() != reversed:
# Wait first.
time.sleep_ms(20)
# Is it still pressed? If so, we have avoided bounce.
if pin.value() != reversed:
return
try:
while True:
# The light should start off.
led.value(0)
wait_for_button(button_on, True)
led.value(1)
wait_for_button(button_off, True)
except:
pass