A collection of examples for using the gpiozero library for reading sensors and activating actuators
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
853 B

3 years ago
from flask import Flask, render_template, Response, request, redirect, url_for
from gpiozero import LED
#This sketch allows you to control an LED from the browser.
#When you run the sketch navigate to yourpi.interaction.tools:8000 to try it
led = LED(17)
app = Flask(__name__)
@app.route("/")
def index():
return render_template('index.html', led_status="Press 'on' or 'off'")
@app.route("/on/", methods=['POST'])
def turn_led_on():
led.on()
led_status = 'LED is on'
#Return the page result
return render_template('index.html', led_status=led_status)
@app.route("/off/", methods=['POST'])
def turn_led_off():
led.off()
led_status= 'LED is off'
#Return the page result
return render_template('index.html', led_status=led_status)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)