-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor_buttons.py
73 lines (61 loc) · 2.6 KB
/
sensor_buttons.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import time
from lib import notify_if_changed
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function from the time module
from cfgmgr import get_config
cfg = get_config()
def yellow_button_callback(channel):
time.sleep(0.1)
if (GPIO.input(int(cfg['buttons']['yellow_button'])) != GPIO.HIGH):
print("Noise Detected Yellow Channel")
else:
print("Yellow button was pushed!")
buzzer_queue.put("beep_once")
queue.put("Triggered")
def green_button_callback(channel):
time.sleep(0.1)
if (GPIO.input(int(cfg['buttons']['green_button'])) != GPIO.HIGH):
print("Noise Detected Green Channel")
else:
print("Green button was pushed!")
buzzer_queue.put("beep_twice")
queue.put("Double")
def white_button_callback(channel):
time.sleep(0.1)
if (GPIO.input(int(cfg['buttons']['white_button'])) != GPIO.HIGH):
print("Noise Detected White Channel")
else:
print("White button was pushed!")
light_queue.put("Toggle")
def blue_button_callback(channel):
time.sleep(0.1)
if (GPIO.input(int(cfg['buttons']['blue_button'])) != GPIO.HIGH):
print("Noise Detected Blue Channel")
else:
print("Blue button was pushed!")
sonos_queue.put("Say_Time")
def check_buttons(local_queue, local_buzzer_queue, local_light_queue, local_sonos_queue):
global queue
queue = local_queue
global buzzer_queue
buzzer_queue = local_buzzer_queue
global light_queue
light_queue = local_light_queue
global sonos_queue
sonos_queue = local_sonos_queue
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BCM) # Use physical pin numbering
# Setup Yellow button
GPIO.setup(int(cfg['buttons']['yellow_button']), GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(int(cfg['buttons']['yellow_button']),GPIO.RISING,callback=yellow_button_callback,bouncetime=500)
# Setup Green button
GPIO.setup(int(cfg['buttons']['green_button']), GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(int(cfg['buttons']['green_button']),GPIO.RISING,callback=green_button_callback,bouncetime=500)
# Setup White button
GPIO.setup(int(cfg['buttons']['white_button']), GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(int(cfg['buttons']['white_button']),GPIO.RISING,callback=white_button_callback,bouncetime=500)
if 'blue_button' in cfg['buttons']:
GPIO.setup(int(cfg['buttons']['blue_button']), GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(int(cfg['buttons']['blue_button']),GPIO.RISING,callback=blue_button_callback,bouncetime=500)
while (True):
time.sleep(100)