-
Notifications
You must be signed in to change notification settings - Fork 0
/
alexa.py
92 lines (76 loc) · 1.91 KB
/
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
#-*- coding: utf-8 -*-
from flask import Flask
from flask_ask import Ask, statement
import RPi.GPIO as GPIO
import time
import os
from omxplayer import OMXPlayer
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(14, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
p = GPIO.PWM(14, 50)
app = Flask(__name__)
ask = Ask(app, '/')
@app.route('/')
def homepage():
return "Raspberry pi LED control"
@ask.launch
def start_skill():
welcome_message = "Hi hyeona, Welcome to Raspberry pi."
return statement(welcome_message)
@ask.intent("LEDOnIntent")
def led_on():
GPIO.output(22, True)
GPIO.output(17, True)
time.sleep(0.5)
text = "ok, LED was Turned on"
return statement(text)
@ask.intent("LEDOffIntent")
def led_off():
GPIO.output(22, False)
GPIO.output(17, False)
time.sleep(0.5)
text = "ok, LED was Turned out"
return statement(text)
@ask.intent("TrunkOpenIntent")
def trunk_open():
GPIO.output(14, True)
p.start(0)
p.ChangeDutyCycle(7.5)
time.sleep(1)
p.stop(0)
text = "ok, trunk was opened"
return statement(text)
@ask.intent("TrunkCloseIntent")
def trunk_close():
GPIO.output(14, True)
p.start(0)
p.ChangeDutyCycle(2.5)
time.sleep(1)
p.stop(0)
text = "ok, trunk was closed"
return statement(text)
@ask.intent("SongIntent")
def music():
text = "wow, exciting song"
file_path='/home/pi/music.mp3'
player=OMXPlayer(file_path)
player.play()
sleep(7)
player.pause()
player.quit()
return statement(text)
@ask.intent("JuneIntent")
def june():
sleep(1)
text = "he is a famous professor who teaches graduation project classes at Seoul Womens's University. and He will give you a A plus grade."
return statement(text)
@ask.intent("HIntent")
def hyuna():
sleep(1)
text = " Sure, It's you."
return statement(text)
if __name__ == "__main__":
app.run(debug = True)