-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_button_lights.py
44 lines (33 loc) · 1.3 KB
/
action_button_lights.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
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 green_button_callback(channel):
print("Green button was pushed!")
buzzer_queue.put("beep_twice")
queue.put("Double")
def set_buttons(queue):
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BCM) # Use physical pin numbering
# Initate buttons (Off by default)
GPIO.setup(int(cfg['buttons']['yellow_led']), GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(int(cfg['buttons']['green_led']), GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(int(cfg['buttons']['white_led']), GPIO.OUT, initial=GPIO.LOW)
# Configure white led with static PWM
#white_pwm = GPIO.PWM(int(cfg['buttons']['white_led']), 100)
#white_pwm.start(20)
# Set default state
state="off"
while (True):
while (not queue.empty()):
state=queue.get()
print state
if (state=="on"):
GPIO.output(int(cfg['buttons']['yellow_led']), GPIO.HIGH)
GPIO.output(int(cfg['buttons']['green_led']), GPIO.HIGH)
else:
GPIO.output(int(cfg['buttons']['yellow_led']), GPIO.LOW)
GPIO.output(int(cfg['buttons']['green_led']), GPIO.LOW)
time.sleep(1)