From 5863b3a0c09b4528335bdd98544235f495770be9 Mon Sep 17 00:00:00 2001 From: Tilman Date: Mon, 27 Nov 2017 21:56:28 +0000 Subject: [PATCH] rgb.py --- code/test/rgb.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 code/test/rgb.py 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()