-
Notifications
You must be signed in to change notification settings - Fork 0
/
threshold_video_trig.py
42 lines (35 loc) · 1.05 KB
/
threshold_video_trig.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
40
41
42
#!/usr/bin/env python3
'''
trigger video playback when analog sensor crosses a value
'''
from video_player import *
from time import sleep
import Adafruit_ADS1x15
BASE_DIR = '/home/cta/'
FILENAME = 'dramatic_chipmunk.mp4'
play_path = ''.join([BASE_DIR, FILENAME])
play = Player(play_path)
adc = Adafruit_ADS1x15.ADS1015()
GAIN = 1
threshold = 500
is_playing = False
try:
print("reading sensor values!")
while True:
sensor_val = adc.read_adc(0, gain=GAIN)
if is_playing == False and sensor_val <= threshold:
print('threshold crossed, starting video')
play.play()
is_playing = True
elif is_playing == True:
if play.status() == 'done':
print(''.join(['done', '\n', '\n']))
is_playing = False
sleep(0.05)
except KeyboardInterrupt:
print(''.join([ '\n', '\n', 'INTERRUPTED', '\n']))
if play.status() == 'playing':
print('video is running, terminating now!')
play.kill()
else:
print('no video running, exiting now')