From eb33823e805eafdd8a8b678ea9f01cda8fa4b925 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Wed, 4 Sep 2024 17:04:12 +0200 Subject: [PATCH] Modifiche per codici di ritorno delle rotte. --- led.py | 5 ++++- webapp.py | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/led.py b/led.py index 239bf2b..844361c 100755 --- a/led.py +++ b/led.py @@ -23,8 +23,11 @@ def lampeggia() -> None: pin_off() time.sleep(0.5) +def stato_pin() -> bool: + return wiringpi.digitalRead(18) + def toggle() -> None: - state = wiringpi.digitalRead(18) + state = stato_pin() if state: pin_off() diff --git a/webapp.py b/webapp.py index df8bcb7..dc4f152 100644 --- a/webapp.py +++ b/webapp.py @@ -12,21 +12,32 @@ def index(): @app.route('/accendi') @app.route('/on') -def accendi() -> None: +def accendi(): led.pin_on() + if led.stato_pin(): + return "LED acceso." + + return "LED Spento." + @app.route('/spegni') @app.route('/off') -def spegni() -> None: +def spegni(): led.pin_off() @app.route('/toggle') -def toggle() -> None: +def toggle(): led.toggle() + if led.stato_pin(): + return "Il LED è acceso." + + return "Il LED è spento." + @app.route('/lampeggia') def lampeggia(): led.lampeggia() + return "LED ha lampeggiato." if __name__ == '__main__': led.setup()