I'm hoping to make a glowing snowman to display during Christmas. I've printed a 3d snowman model and have configured an RGB LED to light up the snowman from inside:
I'm now trying to figure out how to gradually cycle a full spectrum of colours that transitions smoothly between them. As I'm no programmer I've been cobbling the code from various internet sources, but it doesn't do what I'm after.
Would someone be able to help please?
This is what I have so far. It fades to the main colours, but then jumps to the next one as it iterates through the for loop.
Code: Select all
import random, time import RPi.GPIO as GPIO RUNNING = True GPIO.setmode(GPIO.BCM) red = 17 green = 27 blue = 22 GPIO.setup(red, GPIO.OUT) GPIO.setup(green, GPIO.OUT) GPIO.setup(blue, GPIO.OUT) Freq = 100 RED = GPIO.PWM(red, Freq) RED.start(100) GREEN = GPIO.PWM(green, Freq) GREEN.start(100) BLUE = GPIO.PWM(blue, Freq) BLUE.start(100) def color(R, G, B, on_time): RED.ChangeDutyCycle(R) GREEN.ChangeDutyCycle(G) BLUE.ChangeDutyCycle(B) time.sleep(on_time) RED.ChangeDutyCycle(1) GREEN.ChangeDutyCycle(1) BLUE.ChangeDutyCycle(1) try: while RUNNING: for x in range(1,-1,-1): for y in range(1,-1,-1): for z in range(1,-1,-1): print (x,y,z) for i in range(100,-1,-1): color((x*i),(y*i),(z*i), .05) for i in range(0,101): color((x*i),(y*i),(z*i), .05) except KeyboardInterrupt: RUNNING = False print "\Quitting" finally: GPIO.cleanup()