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()