/ examples / pixie_simpletest.py
pixie_simpletest.py
 1  import time
 2  import board
 3  import busio
 4  import adafruit_pixie
 5  
 6  # For use with CircuitPython:
 7  uart = busio.UART(board.TX, rx=None, baudrate=115200)
 8  
 9  # For use on Raspberry Pi/Linux with Adafruit_Blinka:
10  # import serial
11  # uart = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=3000)
12  
13  num_pixies = 2  # Change this to the number of Pixie LEDs you have.
14  pixies = adafruit_pixie.Pixie(uart, num_pixies, brightness=0.2, auto_write=False)
15  
16  
17  def wheel(pos):
18      # Input a value 0 to 255 to get a color value.
19      # The colours are a transition r - g - b - back to r.
20      if pos < 0 or pos > 255:
21          return 0, 0, 0
22      if pos < 85:
23          return int(255 - pos * 3), int(pos * 3), 0
24      if pos < 170:
25          pos -= 85
26          return 0, int(255 - pos * 3), int(pos * 3)
27      pos -= 170
28      return int(pos * 3), 0, int(255 - (pos * 3))
29  
30  
31  while True:
32      for i in range(255):
33          for pixie in range(num_pixies):
34              pixies[pixie] = wheel(i)
35          pixies.show()
36      time.sleep(2)
37      pixies[0] = (0, 255, 0)
38      pixies[1] = (0, 0, 255)
39      pixies.show()
40      time.sleep(1)
41      pixies.fill((255, 0, 0))
42      pixies.show()
43      time.sleep(1)
44      pixies[::2] = [(255, 0, 100)] * (2 // 2)
45      pixies[1::2] = [(0, 255, 255)] * (2 // 2)
46      pixies.show()
47      time.sleep(1)