56 lines
965 B
Python
Executable File
56 lines
965 B
Python
Executable File
#!/usr/bin/env python3
|
|
# encoding: utf-8
|
|
|
|
import wiringpi
|
|
import click
|
|
import time
|
|
|
|
def setup() -> None:
|
|
wiringpi.wiringPiSetupGpio()
|
|
wiringpi.pinMode(18, 1)
|
|
|
|
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 stato_pin() -> bool:
|
|
return wiringpi.digitalRead(18)
|
|
|
|
def toggle() -> None:
|
|
state = stato_pin()
|
|
|
|
if state:
|
|
pin_off()
|
|
else:
|
|
pin_on()
|
|
|
|
# Setup
|
|
@click.command()
|
|
@click.argument('op')
|
|
def cli(op):
|
|
setup()
|
|
|
|
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()
|