This commit is contained in:
2017-11-27 21:56:28 +00:00
parent fb6af3570e
commit 5863b3a0c0
+53
View File
@@ -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()