Skip to content

Instantly share code, notes, and snippets.

@noor-jafri
Created December 27, 2016 12:28
Show Gist options
  • Save noor-jafri/db7b10fc321e61c9413d83dad8259fe4 to your computer and use it in GitHub Desktop.
Save noor-jafri/db7b10fc321e61c9413d83dad8259fe4 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO #Initialising GPIO
import time
# This Code Runs the Flask Web API, you can run on remote RPI or the Local One
#
#
#
#You can add more ports and routes to add further object.
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(17,GPIO.OUT) #Initialising GPIO pins as output
GPIO.setup(18,GPIO.OUT)
GPIO.setup(27,GPIO.OUT)
from flask import Flask # Importing Flask
app = Flask(__name__)
@app.route('/') #Simple Hello World Route
def hello_world():
return 'Hello, World!'
@app.route('/redledon') #Route for Turning RedLed On
def redledon():
GPIO.output(17,GPIO.HIGH) #Turning Pin 17 --> Red Led HIGH
return "Red LED on"
@app.route('/redledoff') #Route for Turning RedLed Off
def redledoff():
GPIO.output(17,GPIO.LOW)
return "Red LED off" #Turning Pin 17 --> Red Led LOW
@app.route('/greenledon')
def greenledon():
GPIO.output(18,GPIO.HIGH)
return "Green LED on"
@app.route('/greenledoff')
def greenledoff():
GPIO.output(18,GPIO.LOW)
return "Green LED off"
@app.route('/blueledon')
def blueledon():
GPIO.output(19,GPIO.HIGH)
return "Blue LED on"
@app.route('/blueledoff')
def blueledoff():
GPIO.output(19,GPIO.LOW)
return "Blue LED off"
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment