-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_alexa.py
executable file
·115 lines (80 loc) · 2.18 KB
/
app_alexa.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
import RPi.GPIO as GPIO
import logging
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session
import multiprocessing
import time
app = Flask(__name__)
ask = Ask(app, "/")
logging.getLogger("flask_ask").setLevel(logging.DEBUG)
GPIO.setmode(GPIO.BCM)
RED = 17
GREEN = 27
BLUE = 24
GPIO.setup(RED, GPIO.OUT)
GPIO.setup(GREEN, GPIO.OUT)
GPIO.setup(BLUE, GPIO.OUT)
def resetColor():
GPIO.output(RED, GPIO.LOW)
GPIO.output(GREEN, GPIO.LOW)
GPIO.output(BLUE, GPIO.LOW)
resetColor()
@ask.intent("LightsOnIntent")
def lightsOn():
# Default to white
resetColor()
GPIO.output(RED, GPIO.HIGH)
GPIO.output(GREEN, GPIO.HIGH)
GPIO.output(BLUE, GPIO.HIGH)
msg = render_template('voice_lightson')
return statement(msg)
@ask.launch
def start_lights_daemon():
lightsOn()
@ask.intent("LightsOffIntent")
def lightsOff():
resetColor()
msg = render_template('voice_lightsoff')
return statement(msg)
@ask.intent("LightsRedIntent")
def lightsRed():
resetColor()
GPIO.output(RED, GPIO.HIGH)
msg = render_template('voice_lightsred')
return statement(msg)
@ask.intent("LightsGreenIntent")
def lightsGreen():
resetColor()
GPIO.output(GREEN, GPIO.HIGH)
msg = render_template('voice_lightsgreen')
return statement(msg)
@ask.intent("LightsBlueIntent")
def lightsBlue():
resetColor()
GPIO.output(BLUE, GPIO.HIGH)
msg = render_template('voice_lightsblue')
return statement(msg)
@ask.intent("LightsPurpleIntent")
def lightsPurple():
resetColor()
GPIO.output(RED, GPIO.HIGH)
GPIO.output(BLUE, GPIO.HIGH)
msg = render_template('voice_lightspurple')
return statement(msg)
@ask.intent("LightsTealIntent")
def lightsTeal():
resetColor()
GPIO.output(BLUE, GPIO.HIGH)
GPIO.output(GREEN, GPIO.HIGH)
msg = render_template('voice_lightsteal')
return statement(msg)
@ask.intent("LightsYellowIntent")
def lightsYellow():
resetColor()
GPIO.output(RED, GPIO.HIGH)
GPIO.output(GREEN, GPIO.HIGH)
msg = render_template("voice_lightsyellow")
return statement(msg)
if __name__ == "__main__":
app.run(debug=True)