Skip to content

Instantly share code, notes, and snippets.

@lindsaylandry
Created March 14, 2017 12:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save lindsaylandry/f30cc0740bc20461edf79f7c452dcc39 to your computer and use it in GitHub Desktop.
Save lindsaylandry/f30cc0740bc20461edf79f7c452dcc39 to your computer and use it in GitHub Desktop.
script to adjust the backlight of pigrrl zero and zero plus using GPIO 27
import os
from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
os.system("gpio -g mode 18 pwm")
os.system("gpio -g pwm 18 1023")
nums = [1023, 500, 200, 50]
i = 0
def my_callback(channel):
global i
global nums
if i >= len(nums) - 1:
i = 0
else:
i = i + 1
os.system("gpio -g pwm 18 %s" % nums[i])
GPIO.remove_event_detect(27)
sleep(0.1)
GPIO.add_event_detect(27, GPIO.FALLING, callback=my_callback, bouncetime=300)
GPIO.add_event_detect(27, GPIO.FALLING, callback=my_callback, bouncetime=300)
try:
while True:
sleep(0.01)
pass
except KeyboardInterrupt:
GPIO.cleanup()
os.system("gpio -g mode 18 in") # 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