/ examples / featherwing_neopixel_simpletest.py
featherwing_neopixel_simpletest.py
 1  """
 2  This example 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 neopixel_featherwing
 9  
10  neopixel = neopixel_featherwing.NeoPixelFeatherWing()
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      neopixel.fill((random_color(), random_color(), random_color()))
21      neopixel.brightness = random.randrange(2, 10) / 10
22      sleep(0.2)
23  
24  # Set display to 30% brightness
25  neopixel.brightness = 0.3
26  
27  # Create a gradiant drawing each pixel
28  for x in range(0, neopixel.columns):
29      for y in range(neopixel.rows - 1, -1, -1):
30          neopixel[x, y] = (y * 63, 255, y * 63)
31  
32  # Rotate everything left 36 frames
33  for i in range(0, 36):
34      neopixel.shift_down(True)
35      sleep(0.1)
36  
37  # Draw dual gradiant and then update
38  # neopixel.auto_write = False
39  for y in range(0, neopixel.rows):
40      for x in range(0, 4):
41          neopixel[x, y] = (y * 16 + 32, x * 8, 0)
42      for x in range(4, 8):
43          neopixel[x, y] = ((4 - y) * 16 + 32, (8 - x) * 8, 0)
44  neopixel.show()
45  
46  # Rotate everything left 36 frames
47  for i in range(0, 36):
48      neopixel.shift_left(True)
49      neopixel.shift_up(True)
50      neopixel.show()
51      sleep(0.1)
52  neopixel.auto_write = True
53  
54  # Shift pixels without rotating for an animated screen wipe
55  for i in range(0, neopixel.rows):
56      neopixel.shift_down()
57      sleep(0.4)
58  
59  # Show pixels in random locations of random color
60  # Bottom left corner is (0,0)
61  while True:
62      x = random.randrange(0, neopixel.columns)
63      y = random.randrange(0, neopixel.rows)
64      neopixel[x, y] = (random_color(), random_color(), random_color())
65      sleep(0.1)