Skip to content

Instantly share code, notes, and snippets.

Created September 24, 2022 19:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
script to run display_all when switch press is registered at GPIO pin
#!/usr/bin/env python3
# based on a script by Alex Eames
import os
import RPi.GPIO as GPIO
# 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
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