How to delay the GPIO when using Flask-ask on Pi

181 Views Asked by At

I've followed a tutorial on getting Amazon Echo to talk to my Raspberry and it works beautifully.

The part I have added is the GPIO parts in the yes intent so that it flashed an LED when it receives a yes answer from the Echo. Again, it works perfectly.

Now I want to make it so there is a delay on the GPIO so that the Alexa response speaks then the LED flashes. How can I do this?

I've tried creating a variable in the yes intent that gets set to '1' when she answers. Then I tried to return it at the end by adding , variableName then creating an if command outside of the yes intent function, but the variable never seems to come out of the yesintent. I also tried defining the variable as global but still no joy. I just can't think of anything else to Google to do this and I wondered if anyone could help?

The code is as follows:

from flask import Flask
from flask_ask import Ask, statement, question, session
import json
import requests
import time
import unidecode
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)

app = Flask(__name__)
ask = Ask(app, "/shocker")

@app.route('/')
def homepage():
    welcome = 'hi there, how the fluff is it?'
    return statement(welcome)

@ask.launch
def start_skill():
    welcome_message = 'Hello there, would you like me to do something?'
    return question(welcome_message)

@ask.intent("YesIntent")
def yes_intent():
    GPIO.setwarnings(False)
    GPIO.setup(7, GPIO.OUT)
    GPIO.output(7,1)
    time.sleep(1)
    GPIO.output(7,0)
    yes_message = 'the thing has been done'
    return statement(yes_message)

@ask.intent("NoIntent")
def no_intent():
    no_message = 'well then why are you wasting my time?'
    return statement(no_message)

if __name__ == '__main__':
    app.run()
0

There are 0 best solutions below