-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBirdBox3-1.py
More file actions
34 lines (28 loc) · 741 Bytes
/
BirdBox3-1.py
File metadata and controls
34 lines (28 loc) · 741 Bytes
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
34
from machine import Pin, Timer
import time
def wait_pin_change(pin):
"Debounce a GPIO input"
# wait for pin to change value
# it needs to be stable for a continuous 20ms
cur_value = pin.value()
active = 0
while active < 20:
if pin.value() != cur_value:
active += 1
else:
active = 0
time.sleep_ms(1)
return cur_value
led = Pin(25, Pin.OUT)
pwr = Pin(22, Pin.OUT, value=1)
btn = Pin(12, Pin.IN, Pin.PULL_UP)
timer = Timer()
def blink(timer):
led.toggle()
#timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
enable = True
while True:
led.value(enable)
pwr.value(enable)
if 0 == wait_pin_change(btn):
enable = not enable