raspiled/webapp.py

45 lines
696 B
Python
Raw Normal View History

2024-09-04 16:53:56 +02:00
#!/usr/bin/env python3
# encoding: utf-8
from flask import Flask
import led
app = Flask(__name__)
@app.route('/')
def index():
return "Benvenuto nel raspberry."
@app.route('/accendi')
@app.route('/on')
def accendi():
2024-09-04 16:53:56 +02:00
led.pin_on()
if led.stato_pin():
return "LED acceso."
return "LED Spento."
2024-09-04 16:53:56 +02:00
@app.route('/spegni')
@app.route('/off')
def spegni():
2024-09-04 16:53:56 +02:00
led.pin_off()
@app.route('/toggle')
def toggle():
2024-09-04 16:53:56 +02:00
led.toggle()
if led.stato_pin():
return "Il LED è acceso."
return "Il LED è spento."
2024-09-04 16:53:56 +02:00
@app.route('/lampeggia')
def lampeggia():
led.lampeggia()
return "LED ha lampeggiato."
2024-09-04 16:53:56 +02:00
if __name__ == '__main__':
led.setup()
app()