I'm currently creating a program to make it possilble to control a multi-colour-LED with a python GUI. The GUI itself and everything else works fine, I'm just still having problems with creating a switch-function. I got a simple configuration for the Multi colour LED:
Pin 19: to green Pin 21: to blue Pin 23: to red Pin 25: works as the GND for the LED
Now I have got this code:
import RPi.GPIO as GPIO import time, sys green = 0 blue = 0 #those are the status of the single LED inside of the red = 0 #multi colour LED(being off, so 0, at the start) GPIO.setmode(GPIO.BOARD) GPIO.setup(19, GPIO.OUT) GPIO.setup(21, GPIO.OUT) GPIO.setup(23, GPIO.OUT) GPIO.output(19, green) GPIO.output(21, blue) GPIO.output(23, red) def switch(pin, colour): colour = not colour GPIO.output(pin, colour) return try: while True: switch(19, green) time.sleep(0.5) switch(21, blue) time.sleep(0.5) switch(23, red) time.sleep(0.5) except KeyboardInterrupt: GPIO.cleanup() sys.exit()
My main focus is on the switch function, since it can turn the single LED's on but can't turn them off again.
What could be the problem here and how to solve it?