Last active
July 27, 2019 12:37
-
-
Save Akkiesoft/4a664e14e575bd4194ad124c3fc5c475 to your computer and use it in GitHub Desktop.
Demo script for Inky pHAT with Button SHIM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Demo script for Inky pHAT with Button SHIM | |
Push any buttons then run the Inky pHAT demo script. | |
After pressing the button, you should wait for 2 minutes | |
because prevent it being executed frequently. | |
This script should save following path | |
(Inky pHAT demo script uses relative paths): | |
/home/pi/Pimoroni/inkyphat/examples/inky-demo.py | |
photo: https://social.mikutter.hachune.net/@akkiesoft/99606843419283531 | |
""" | |
import signal | |
import buttonshim | |
import subprocess | |
import time | |
running = 0 | |
buttonshim.set_brightness(0.1) | |
sleeptime = 120 | |
buttonshim.set_pixel(0x00, 0xff, 0x00) | |
@buttonshim.on_press(buttonshim.BUTTON_A) | |
def button_a(button, pressed): | |
run_program(["/usr/bin/python","/home/pi/Pimoroni/inkyphat/examples/cal.py"]) | |
@buttonshim.on_press(buttonshim.BUTTON_B) | |
def button_b(button, pressed): | |
run_program(["/usr/bin/python","/home/pi/Pimoroni/inkyphat/examples/weather.py"]) | |
@buttonshim.on_press(buttonshim.BUTTON_C) | |
def button_c(button, pressed): | |
run_program(["/usr/bin/python","/home/pi/Pimoroni/inkyphat/examples/hello.py","Raspberry Pi"]) | |
@buttonshim.on_press(buttonshim.BUTTON_D) | |
def button_d(button, pressed): | |
run_program(["/usr/bin/python","/home/pi/Pimoroni/inkyphat/examples/qr.py"]) | |
# @buttonshim.on_press(buttonshim.BUTTON_E) | |
# def button_e(button, pressed): | |
def run_program(program): | |
global running, sleeptime | |
if not running: | |
buttonshim.set_pixel(0xff, 0x00, 0x00) | |
running = 1 | |
subprocess.Popen(program) | |
time.sleep(sleeptime/2) | |
buttonshim.set_pixel(0xff, 0xff, 0x00) | |
time.sleep(sleeptime/2) | |
buttonshim.set_pixel(0x00, 0xff, 0x00) | |
running = 0 | |
else: | |
for x in range(2): | |
buttonshim.set_pixel(0x00, 0x00, 0x00) | |
time.sleep(0.25) | |
buttonshim.set_pixel(0xff, 0x00, 0x00) | |
time.sleep(0.25) | |
signal.pause() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment