Last active
August 31, 2016 05:29
-
-
Save rxseger/20e999b490b6709594c49b6f3ecca742 to your computer and use it in GitHub Desktop.
CD/DVD ROM tray open/closed switch GPIO script for Raspberry Pi
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/python | |
| # turn on yellow LED when CD/DVD tray fully open, blue LED when fully closed | |
| import RPi.GPIO as GPIO | |
| import time | |
| GPIO.setmode(GPIO.BOARD) | |
| OPSW = 22 # G25 | |
| CLSW = 37 # G26 | |
| LED_Y = 32 # G12 | |
| LED_B = 33 # G13 | |
| GPIO.setwarnings(False) | |
| GPIO.setup([OPSW, CLSW], GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
| GPIO.setup([LED_Y, LED_B], GPIO.OUT, initial=GPIO.HIGH) | |
| def handle(pin): | |
| value = GPIO.input(pin) | |
| if pin == OPSW: | |
| GPIO.output(LED_Y, value) | |
| elif pin == CLSW: | |
| GPIO.output(LED_B, value) | |
| GPIO.add_event_detect(OPSW, GPIO.BOTH, handle) | |
| GPIO.add_event_detect(CLSW, GPIO.BOTH, handle) | |
| while True: | |
| time.sleep(1e6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment