Skip to content

Instantly share code, notes, and snippets.

@seantibor
Created May 31, 2019 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seantibor/abc89cbd2b082f589c01a763fa83ca4e to your computer and use it in GitHub Desktop.
Save seantibor/abc89cbd2b082f589c01a763fa83ca4e 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.
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