Skip to content

Instantly share code, notes, and snippets.

@FliegendeWurst
Created September 24, 2022 19:15
Show Gist options
  • Save FliegendeWurst/087916a7635c2690de609366517a4ae7 to your computer and use it in GitHub Desktop.
Save FliegendeWurst/087916a7635c2690de609366517a4ae7 to your computer and use it in GitHub Desktop.
script to run display_all when switch press is registered at GPIO pin
#!/usr/bin/env python3
# based on a script by Alex Eames https://raspi.tv/
# https://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# GPIO 19 set up as input, pull-down to register more than one switch use.
GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# trigger each action in turn
actions = ["temps", "events"]
i = 0
try:
while True:
GPIO.wait_for_edge(19, GPIO.RISING)
os.system("./display_off on")
# replace this path on every deploy
os.system("/nix/store/ia5b02zam4h8qwsjc2r11hqpl95qk32m-raspi-oled-armv6l-unknown-linux-musleabihf-unstable-infdev-2/bin/display_all sensors.db events.json " + actions[i % len(actions)])
i += 1
except KeyboardInterrupt:
GPIO.cleanup() # clean up GPIO on CTRL+C exit
GPIO.cleanup() # clean up GPIO on normal exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment