Ich mach ja alles, was man mir sagt:
Python
#!/usr/bin/env python3
from gpiozero import Button, LEDBoard
from signal import pause
import warnings, os, sys
import subprocess
offGPIO = int(sys.argv[1]) if len(sys.argv) >= 2 else 3
offtime = int(sys.argv[2]) if len(sys.argv) >= 3 else 6
mintime = 1 # notice switch after mintime seconds
LEDGruenGPIO = 7 # Gruene LED
LEDRotGPIO = 8 # Rote LED
def shutdown(b):
# find how long the button has been held
p = b.pressed_time
# blink rate will increase the longer we hold
# the button down. E.g., at 2 seconds, use 1/4 second rate.
leds.blink(on_time=0.5/p, off_time=0.5/p)
if p > offtime:
subprocess.Popen(['shutdown','-h','now'])
def when_pressed():
# start blinking with 1/2 second rate
leds.blink(on_time=0.5, off_time=0.5)
def when_released():
# be sure to turn the LEDs off if we release early
leds.off()
leds = LEDBoard(LEDRotGPIO)
btn = Button(offGPIO, hold_time=mintime, hold_repeat=True)
btn.when_held = shutdown
btn.when_pressed = when_pressed
btn.when_released = when_released
pause()
Alles anzeigen
ob das jetzt richtig war, weiß ich nicht, funktioniert aber