Created
March 14, 2017 12:56
-
-
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
This file contains 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
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