-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (31 loc) · 909 Bytes
/
main.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
34
35
36
37
38
39
### author: Laurie James
### description: Goes in a bin. Plays r2d2 noises when the bin shuts. Useful to probably no one but me.
### license: MIT
### reboot-before-run: True
### Appname: R2D2-bin
from http_client import get
import pyb
from imu import IMU
import wifi
TILT_THRESHOLD = -0.4
TILT_PLAY = -0.1
imu = IMU()
host = 'http://192.168.0.12:8001'
if not wifi.nic().is_connected():
wifi.connect(timeout=20)
triggered = False
while(True):
y = imu.get_acceleration()['y']
if(int(y) < TILT_THRESHOLD):
triggered = True
elif(y > TILT_PLAY and triggered):
try:
print('foobar')
get(host, timeout=10).raise_for_status()
except Exception as e:
print('Request Failed {}'.format(str(e)))
except OSError as e:
print('Request Failed {}'.format(str(e)))
finally:
triggered = False
pyb.delay(500)