From b06470d57f1f3f055c4adb30abf4a44795c19e5d Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Wed, 4 Sep 2024 16:05:53 +0200 Subject: [PATCH] Script per linea di comando. --- .gitignore | 1 + led.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ 3 files changed, 52 insertions(+) create mode 100644 .gitignore create mode 100755 led.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv diff --git a/led.py b/led.py new file mode 100755 index 0000000..f67b268 --- /dev/null +++ b/led.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# encoding: utf-8 + +import wiringpi +import click +import time + +def pin_on() -> None: + # Attiva uscita GPIO18 + wiringpi.digitalWrite(18, 1) + +def pin_off() -> None: + wiringpi.digitalWrite(18, 0) + +def lampeggia() -> None: + for x in range(0, 4): + pin_on() + time.sleep(0.5) + pin_off() + time.sleep(0.5) + +def toggle() -> None: + state = wiringpi.digitalRead(18) + + if state: + pin_off() + else: + pin_on() + +# Setup +@click.command() +@click.argument('op') +def cli(op): + wiringpi.wiringPiSetupGpio() + wiringpi.pinMode(18, 1) + + if op in [ "accendi", "on" ]: + pin_on() + elif op in [ "spegni", "off" ]: + pin_off() + elif op == 'lampeggia': + lampeggia() + elif op == 'toggle': + toggle() + else: + click.echo("Che vuoi da me?") + +if __name__ == '__main__': + cli() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2ce2f60 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +wiringpi +click