Modifiche per codici di ritorno delle rotte.

This commit is contained in:
Emiliano Vavassori 2024-09-04 17:04:12 +02:00
parent 25cb3c95f0
commit eb33823e80
2 changed files with 18 additions and 4 deletions

5
led.py
View File

@ -23,8 +23,11 @@ def lampeggia() -> None:
pin_off() pin_off()
time.sleep(0.5) time.sleep(0.5)
def stato_pin() -> bool:
return wiringpi.digitalRead(18)
def toggle() -> None: def toggle() -> None:
state = wiringpi.digitalRead(18) state = stato_pin()
if state: if state:
pin_off() pin_off()

View File

@ -12,21 +12,32 @@ def index():
@app.route('/accendi') @app.route('/accendi')
@app.route('/on') @app.route('/on')
def accendi() -> None: def accendi():
led.pin_on() led.pin_on()
if led.stato_pin():
return "LED acceso."
return "LED Spento."
@app.route('/spegni') @app.route('/spegni')
@app.route('/off') @app.route('/off')
def spegni() -> None: def spegni():
led.pin_off() led.pin_off()
@app.route('/toggle') @app.route('/toggle')
def toggle() -> None: def toggle():
led.toggle() led.toggle()
if led.stato_pin():
return "Il LED è acceso."
return "Il LED è spento."
@app.route('/lampeggia') @app.route('/lampeggia')
def lampeggia(): def lampeggia():
led.lampeggia() led.lampeggia()
return "LED ha lampeggiato."
if __name__ == '__main__': if __name__ == '__main__':
led.setup() led.setup()