Its from a github:https://github.com/TonyLHansen/raspberr ... edboard.py
The problem I am having is figuring out how to manipulate it, I would like to be able to adjust the amount of time the button is pressed for before initiating a shutdown. How do i do that in this script?
Code: Select all
#!/usr/bin/env python3 from gpiozero import Button, LEDBoard from signal import pause import warnings, os, sys offGPIO = int(sys.argv) if len(sys.argv) >= 2 else 21 offtime = int(sys.argv) if len(sys.argv) >= 3 else 6 mintime = 1 # notice switch after mintime seconds actledGPIO = 47 # activity LED powerledGPIO = 35 # power 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: os.system("sudo poweroff") 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() with warnings.catch_warnings(): warnings.simplefilter("ignore") leds = LEDBoard(actledGPIO, powerledGPIO) btn = Button(offGPIO, hold_time=mintime, hold_repeat=True) btn.when_held = shutdown btn.when_pressed = when_pressed btn.when_released = when_released pause()
And do I need to run it as python3 or will python be fine?
The script does work for me, but there is a long pause between initiating shutdown and it actually happening when compared to other scripts.
Also, what is the difference between running this as a cron job and using rc.local?