/ examples / trellism4_neopixel_simpletest.py
trellism4_neopixel_simpletest.py
 1  """Test your Trellis M4 Express without needing the serial output.
 2  Press any button and the rest will light up the same color!"""
 3  import time
 4  import adafruit_trellism4
 5  
 6  trellis = adafruit_trellism4.TrellisM4Express()
 7  
 8  
 9  def wheel(pos):
10      if pos < 0 or pos > 255:
11          return 0, 0, 0
12      if pos < 85:
13          return int(255 - pos * 3), int(pos * 3), 0
14      if pos < 170:
15          pos -= 85
16          return 0, int(255 - pos * 3), int(pos * 3)
17      pos -= 170
18      return int(pos * 3), 0, int(255 - (pos * 3))
19  
20  
21  for x in range(trellis.pixels.width):
22      for y in range(trellis.pixels.height):
23          pixel_index = ((y * 8) + x) * 256 // 32
24          trellis.pixels[x, y] = wheel(pixel_index & 255)
25  
26  
27  current_press = set()
28  while True:
29      pressed = set(trellis.pressed_keys)
30      for press in pressed - current_press:
31          if press:
32              print("Pressed:", press)
33              pixel = (press[1] * 8) + press[0]
34              pixel_index = pixel * 256 // 32
35              trellis.pixels.fill(wheel(pixel_index & 255))
36      for release in current_press - pressed:
37          if release:
38              print("Released:", release)
39              for x in range(trellis.pixels.width):
40                  for y in range(trellis.pixels.height):
41                      pixel_index = ((y * 8) + x) * 256 // 32
42                      trellis.pixels[x, y] = wheel(pixel_index & 255)
43      time.sleep(0.08)
44      current_press = pressed