diff --git a/code/test/rgb.py b/code/test/rgb.py new file mode 100644 index 0000000..c3731c1 --- /dev/null +++ b/code/test/rgb.py @@ -0,0 +1,53 @@ +import RPi.GPIO as GPIO +import time + +GPIO.setmode(GPIO.BCM) + +RUNNING = True + +# PINs +green = 20 +red = 21 +blue = 22 + +# frequency for PWM +freq = 100 + +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()