Script per linea di comando.

This commit is contained in:
Emiliano Vavassori 2024-09-04 16:05:53 +02:00
commit b06470d57f
3 changed files with 52 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
venv

49
led.py Executable file
View File

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

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
wiringpi
click