Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
# 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
You can’t perform that action at this time.