Last active
July 10, 2020 06:55
-
-
Save davidsword/c0b220e81734846578151ac34b61ea80 to your computer and use it in GitHub Desktop.
https://davidsword.ca/a-cheaper-diy-status-light/ - Raspberry Pi control a common anode or common cathode RGB LED. e sure to know the difference of your RGB LED. Usage: `python3 rgb-led-status.py <avaliable|busy|offline>` to set as green, red, or off respectively.
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
# https://davidsword.ca/a-cheaper-diy-status-light/ | |
import sys | |
import RPi.GPIO as GPIO | |
GPIO.setwarnings(False) | |
# Note this is BOARD numbering. | |
GPIO.setmode(GPIO.BOARD) | |
redPin = 3 | |
greenPin = 5 | |
bluePin = 7 | |
# set to false if using a RGB LED with common Anode. | |
commonCath = True | |
GPIO.setup(redPin, GPIO.OUT, initial=0) | |
GPIO.setup(greenPin, GPIO.OUT, initial=0) | |
GPIO.setup(bluePin, GPIO.OUT, initial=0) | |
if commonCath: | |
setOn = 1 | |
setOff = 0 | |
else: | |
setOn = 0 | |
setOff = 1 | |
def turnOn(pin): | |
GPIO.output(pin, setOn) | |
def turnOff(pin): | |
GPIO.output(pin, setOff) | |
def main(): | |
cmd = sys.argv[1] | |
if cmd == "busy": | |
turnOff(greenPin) | |
turnOn(redPin) | |
elif cmd == "available": | |
turnOn(greenPin) | |
turnOff(redPin) | |
elif cmd == "offline": | |
turnOff(greenPin) | |
turnOff(redPin); | |
else: | |
print("Not a valid command") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment