import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) RUNNING = True # PINs red = 20 green = 21 blue = 22 # frequency for PWM freq = 50 GPIO.setup(red, GPIO.OUT) GPIO.setup(green, GPIO.OUT) GPIO.setup(blue, GPIO.OUT) # defining the pins that are going to be used with PWM RED = GPIO.PWM(red, freq) GREEN = GPIO.PWM(green, freq) BLUE = GPIO.PWM(blue, freq) colors = [RED,GREEN,BLUE] try: while RUNNING: RED.start(100) GREEN.start(1) BLUE.start(1) for x in range(3): full = colors[x] up = colors[(x+1)%3] zero = colors[(x+2)%3] full.ChangeDutyCycle(100) zero.ChangeDutyCycle(1) # Keep one color at 100%, let another raise from 1% to 100% and leave the third at 1% for y in range(1,101): up.ChangeDutyCycle(y) time.sleep(0.01) # Now keep the raised color at 100% and dim the original full color down to 1% for y in range(1,101): full.ChangeDutyCycle(100-y) time.sleep(0.01) except KeyboardInterrupt: RUNNING = False GPIO.cleanup()