NB: this version doesn’t actually do the rebooting or shutting down: it’s a demo. This one does, though …
Here’s how you might have just one button being a reset button (hold down for two seconds) or a shutdown button (hold down for five):
work as if you live in the early days of a better nation
NB: this version doesn’t actually do the rebooting or shutting down: it’s a demo. This one does, though …
Here’s how you might have just one button being a reset button (hold down for two seconds) or a shutdown button (hold down for five):
Good stuff, Russel. Was making a shutdown button for my OSMC Raspberry Pi based on the article in MagPie57. Then, it occurred to me that it would be great to have one button rather than separate shutdown and reset buttons as mentioned there. After dabbling for a while (and learning lots about the GPIOzero library), I came across your post. The hold_repeat option was the bit that I was missing.
Now it all works beautifully.
Remark regarding systemd: I appended the /etc/rc.local file to start up the little program at boot. Seems to work just fine. Any thoughts on systemd vs. rc.local?
Cheers
rc.local is dead; systemd is the only game in town now.
Thanks scruss! saved me a lot of time trying to create this myself (my python sucks).
Question: was the indent on line 23 intentional? Did you intend to only clear the held_for timer for the case of 2 secs, the held_for gets locked at that value regardless of how long the next the button press was.
For my testing I moved ‘held_for = 0.0’ outside of the if/else loop and it worked more like I expected.
Yep, intentional. Otherwise you could tap the button lots of short times and it would add up and finally reboot.
But don’t use this version. This is newer: https://scruss.com/blog/2017/10/21/combined-restart-shutdown-button-for-raspberry-pi/
Better still, use the thing that’s built into Raspberry Pi OS: gpio-shutdown in config.txt