forked from doniks/pycom-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpin_sleep_wake.py
More file actions
32 lines (27 loc) · 821 Bytes
/
pin_sleep_wake.py
File metadata and controls
32 lines (27 loc) · 821 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
import machine
from machine import Pin
import pycom
import time
pins = ["P2", "P3", "P4"]
#pins = ["P4"]
pins = ["P13"]
# P2, P3, P4, P6, P8 to P10 and P13 to P23
wake_on_rise = True
s = 60000
if wake_on_rise:
print("Device will wake when any of", pins, "is raised high")
wake_pins = []
for p in pins:
wake_pins += [Pin(p, mode=Pin.IN, pull=Pin.PULL_DOWN)]
machine.pin_sleep_wakeup(wake_pins, machine.WAKEUP_ANY_HIGH, True)
else:
print("Device will wake when all of", pins, "are pulled low")
wake_pins = []
for p in pins:
wake_pins += [Pin(p, mode=Pin.IN, pull=Pin.PULL_UP)]
machine.pin_sleep_wakeup(wake_pins, machine.WAKEUP_ALL_LOW, True)
print("deepsleep for", s / 1000, "seconds")
pycom.heartbeat(False)
pycom.rgbled(0x222200)
time.sleep(0.5)
machine.deepsleep(s)