-
-
Save gwthompson/b5dffbf242d88ccf53911ff5b3364fce to your computer and use it in GitHub Desktop.
uses the Adafruit wheel function and a generator to iterate back and forth over a range of colors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from adafruit_circuitplayground.express import cpx | |
import time | |
def wheel(pos): | |
# Input a value 0 to 255 to get a color value. | |
# The colours are a transition r - g - b - back to r. | |
if pos < 0 or pos > 255: | |
return (0, 0, 0) | |
if pos < 85: | |
return (255 - pos * 3, pos * 3, 0) | |
if pos < 170: | |
pos -= 85 | |
return (0, 255 - pos * 3, pos * 3) | |
pos -= 170 | |
return (pos * 3, 0, 255 - pos * 3) | |
def cycle_colors(startpos=0, endpos=255, step=1): | |
i = startpos | |
step = -step | |
while True: | |
print(i) | |
yield wheel(i) | |
if startpos >= i or i >= endpos: | |
step = -step | |
i += step | |
color = cycle_colors(startpos=150, endpos=225,step=3) | |
while True: | |
for i in range(len(cpx.pixels)): | |
cpx.pixels[i] = next(color) | |
cpx.pixels.show() | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment