Created
January 26, 2015 22:49
-
-
Save Andygmb/b4f9a9bdd139cf5bb4ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
import RPi.GPIO as GPIO | |
import Queue | |
import threading | |
import time | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return render_template("buttons.html") | |
@app.route("/<colour>/<value>/") | |
def turn_on_or_off(colour, value): | |
global looping | |
looping = bool(int(value)) | |
NewThread(loop_till_false).start() | |
return "Anything" | |
def loop_till_false(): | |
while looping: | |
GPIO.output(4, True) | |
time.sleep(1) | |
GPIO.output(4, False) | |
time.sleep(1) | |
class NewThread(threading.Thread): | |
def __init__(self, callback_function): | |
threading.Thread.__init__(self) | |
self.callback_function = callback_function | |
def run(self): | |
self.callback_function() | |
if __name__ == "__main__": | |
global GPIO | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(4, GPIO.OUT) | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment