featherwing_dotstar_simpletest.py
1 """ 2 This plays various animations 3 and then draws random pixels at random locations 4 """ 5 6 from time import sleep 7 import random 8 from adafruit_featherwing import dotstar_featherwing 9 10 dotstar = dotstar_featherwing.DotStarFeatherWing() 11 12 # HELPERS 13 # a random color 0 -> 224 14 def random_color(): 15 return random.randrange(0, 8) * 32 16 17 18 # Fill screen with random colors at random brightnesses 19 for i in range(0, 5): 20 dotstar.fill((random_color(), random_color(), random_color())) 21 dotstar.brightness = random.randrange(2, 10) / 10 22 sleep(0.2) 23 24 # Set display to 30% brightness 25 dotstar.brightness = 0.3 26 27 # Create a gradiant drawing each pixel 28 for x in range(0, dotstar.columns): 29 for y in range(dotstar.rows - 1, -1, -1): 30 dotstar[x, y] = (y * 42, 255, y * 42, 1) 31 32 # Rotate everything left 36 frames 33 for i in range(0, 36): 34 dotstar.shift_down(True) 35 36 # Draw dual gradiant and then update 37 dotstar.auto_write = False 38 for y in range(0, dotstar.rows): 39 for x in range(0, 6): 40 dotstar[x, y] = (y * 84, x * 42, x * 42, 1) 41 for x in range(6, 12): 42 dotstar[x, y] = (255 - (y * 84), 255 - ((x - 6) * 42), 255 - ((x - 6) * 42), 1) 43 44 # Rotate everything left 36 frames 45 for i in range(0, 36): 46 dotstar.shift_left(True) 47 dotstar.shift_up(True) 48 dotstar.show() 49 dotstar.auto_write = True 50 51 # Shift pixels without rotating for an animated screen wipe 52 for i in range(0, 6): 53 dotstar.shift_down() 54 55 # Show pixels in random locations of random color 56 # Bottom left corner is (0,0) 57 while True: 58 x = random.randrange(0, dotstar.columns) 59 y = random.randrange(0, dotstar.rows) 60 dotstar[x, y] = (random_color(), random_color(), random_color()) 61 sleep(0.1)