Created
March 2, 2020 02:40
-
-
Save FoamyGuy/939d3ff02fc7ea462d2609b958693e78 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Drive NeoPixels on the NeoPixels Block on Crickit FeatherWing | |
import time | |
from adafruit_crickit import crickit | |
from adafruit_seesaw.neopixel import NeoPixel | |
num_pixels = 30 # Number of pixels driven from Crickit NeoPixel terminal | |
# The following line sets up a NeoPixel strip on Seesaw pin 20 for Feather | |
pixels = NeoPixel(crickit.seesaw, 20, num_pixels) | |
pixels.brightness = 0.02 | |
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 color_chase(color, wait): | |
for i in range(num_pixels): | |
pixels[i] = color | |
time.sleep(wait) | |
pixels.show() | |
time.sleep(0.5) | |
def rainbow_cycle(wait): | |
for j in range(255): | |
for i in range(num_pixels): | |
rc_index = (i * 256 // num_pixels) + j | |
pixels[i] = wheel(rc_index & 255) | |
pixels.show() | |
time.sleep(wait) | |
RED = (255, 0, 0) | |
YELLOW = (255, 150, 0) | |
GREEN = (0, 255, 0) | |
CYAN = (0, 255, 255) | |
BLUE = (0, 0, 255) | |
PURPLE = (180, 0, 255) | |
while True: | |
print("fill") | |
pixels.fill(RED) | |
pixels.show() | |
# Increase or decrease to change the speed of the solid color change. | |
time.sleep(1) | |
pixels.fill(GREEN) | |
pixels.show() | |
time.sleep(1) | |
pixels.fill(BLUE) | |
pixels.show() | |
time.sleep(1) | |
print("chase") | |
color_chase(RED, 0.1) # Increase the number to slow down the color chase | |
color_chase(YELLOW, 0.1) | |
color_chase(GREEN, 0.1) | |
color_chase(CYAN, 0.1) | |
color_chase(BLUE, 0.1) | |
color_chase(PURPLE, 0.1) | |
print("rainbow") | |
rainbow_cycle(0) # Increase the number to slow down the rainbow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment