# CircuitPython demo - Dotstar import time import board import adafruit_dotstar num_pixels = 30 pixels = adafruit_dotstar.DotStar(board.A1, board.A2, num_pixels, brightness=0.1, auto_write=False) 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 slice_alternating(wait): pixels[::2] = [RED] * (num_pixels // 2) pixels.show() time.sleep(wait) pixels[1::2] = [ORANGE] * (num_pixels // 2) pixels.show() time.sleep(wait) pixels[::2] = [YELLOW] * (num_pixels // 2) pixels.show() time.sleep(wait) pixels[1::2] = [GREEN] * (num_pixels // 2) pixels.show() time.sleep(wait) pixels[::2] = [TEAL] * (num_pixels // 2) pixels.show() time.sleep(wait) pixels[1::2] = [CYAN] * (num_pixels // 2) pixels.show() time.sleep(wait) pixels[::2] = [BLUE] * (num_pixels // 2) pixels.show() time.sleep(wait) pixels[1::2] = [PURPLE] * (num_pixels // 2) pixels.show() time.sleep(wait) pixels[::2] = [MAGENTA] * (num_pixels // 2) pixels.show() time.sleep(wait) pixels[1::2] = [WHITE] * (num_pixels // 2) pixels.show() time.sleep(wait) def slice_rainbow(wait): pixels[::6] = [RED] * (num_pixels // 6) pixels.show() time.sleep(wait) pixels[1::6] = [ORANGE] * (num_pixels // 6) pixels.show() time.sleep(wait) pixels[2::6] = [YELLOW] * (num_pixels // 6) pixels.show() time.sleep(wait) pixels[3::6] = [GREEN] * (num_pixels // 6) pixels.show() time.sleep(wait) pixels[4::6] = [BLUE] * (num_pixels // 6) pixels.show() time.sleep(wait) pixels[5::6] = [PURPLE] * (num_pixels // 6) pixels.show() time.sleep(wait) 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) ORANGE = (255, 40, 0) GREEN = (0, 255, 0) TEAL = (0, 255, 120) CYAN = (0, 255, 255) BLUE = (0, 0, 255) PURPLE = (180, 0, 255) MAGENTA = (255, 0, 20) WHITE = (255, 255, 255) while True: pixels.fill(RED) pixels.show() time.sleep(0.5) # Change this number to change how long it stays on each solid color. pixels.fill(ORANGE) pixels.show() time.sleep(0.5) pixels.fill(YELLOW) pixels.show() time.sleep(0.5) pixels.fill(GREEN) pixels.show() time.sleep(0.5) pixels.fill(TEAL) pixels.show() time.sleep(0.5) pixels.fill(CYAN) pixels.show() time.sleep(0.5) pixels.fill(BLUE) pixels.show() time.sleep(0.5) pixels.fill(PURPLE) pixels.show() time.sleep(0.5) pixels.fill(MAGENTA) pixels.show() time.sleep(0.5) pixels.fill(WHITE) pixels.show() time.sleep(0.5) slice_alternating(0.1) # Increase or decrease this to speed up or slow down the animation. pixels.fill(WHITE) pixels.show() time.sleep(0.5) slice_rainbow(0.1) # Increase or decrease this to speed up or slow down the animation. time.sleep(0.5) rainbow_cycle(0) # Increase this number to slow down the rainbow animation.