Advertisement
Arbitrator

Untitled

May 29th, 2019
6,911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | None | 0 0
  1. # CircuitPlaygroundExpress_NeoPixel
  2.  
  3. import time
  4.  
  5. import board
  6. import neopixel
  7.  
  8. pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.2)
  9. pixels.fill((0, 0, 0))
  10. pixels.show()
  11.  
  12. # choose which demos to play
  13. # 1 means play, 0 means don't!
  14. simpleCircleDemo = 1
  15. flashDemo = 1
  16. rainbowDemo = 1
  17. rainbowCycleDemo = 1
  18.  
  19.  
  20. def wheel(pos):
  21.     # Input a value 0 to 255 to get a color value.
  22.     # The colours are a transition r - g - b - back to r.
  23.     if pos < 85:
  24.         return (int(pos * 3), int(255 - (pos * 3)), 0)
  25.     elif pos < 170:
  26.         pos -= 85
  27.         return (int(255 - (pos * 3)), 0, int(pos * 3))
  28.     else:
  29.         pos -= 170
  30.         return (0, int(pos * 3), int(255 - pos * 3))
  31.  
  32.  
  33. def rainbow_cycle(wait):
  34.     for j in range(255):
  35.         for i in range(len(pixels)):
  36.             idx = int((i * 256 / len(pixels)) + j * 10)
  37.             pixels[i] = wheel(idx & 255)
  38.         pixels.show()
  39.         time.sleep(wait)
  40.  
  41.  
  42. def rainbow(wait):
  43.     for j in range(255):
  44.         for i in range(len(pixels)):
  45.             idx = int(i + j)
  46.             pixels[i] = wheel(idx & 255)
  47.         pixels.show()
  48.         time.sleep(wait)
  49.  
  50.  
  51. def simpleCircle(wait):
  52.     RED = 0x100000  # (0x10, 0, 0) also works
  53.     YELLOW = (0x10, 0x10, 0)
  54.     GREEN = (0, 0x10, 0)
  55.     AQUA = (0, 0x10, 0x10)
  56.     BLUE = (0, 0, 0x10)
  57.     PURPLE = (0x10, 0, 0x10)
  58.     BLACK = (0, 0, 0)
  59.  
  60.     for i in range(len(pixels)):
  61.         pixels[i] = RED
  62.         time.sleep(wait)
  63.     time.sleep(1)
  64.  
  65.     for i in range(len(pixels)):
  66.         pixels[i] = YELLOW
  67.         time.sleep(wait)
  68.     time.sleep(1)
  69.  
  70.     for i in range(len(pixels)):
  71.         pixels[i] = GREEN
  72.         time.sleep(wait)
  73.     time.sleep(1)
  74.  
  75.     for i in range(len(pixels)):
  76.         pixels[i] = AQUA
  77.         time.sleep(wait)
  78.     time.sleep(1)
  79.  
  80.     for i in range(len(pixels)):
  81.         pixels[i] = BLUE
  82.         time.sleep(wait)
  83.     time.sleep(1)
  84.  
  85.     for i in range(len(pixels)):
  86.         pixels[i] = PURPLE
  87.         time.sleep(wait)
  88.     time.sleep(1)
  89.  
  90.     for i in range(len(pixels)):
  91.         pixels[i] = BLACK
  92.         time.sleep(wait)
  93.     time.sleep(1)
  94.  
  95.  
  96. while True:
  97.     if simpleCircleDemo:
  98.         print('Simple Circle Demo')
  99.         simpleCircle(.05)
  100.  
  101.     if flashDemo:  # this will play if flashDemo = 1 up above
  102.         print('Flash Demo')
  103.         pixels.fill((255, 0, 0))
  104.         pixels.show()
  105.         time.sleep(.25)
  106.  
  107.         pixels.fill((0, 255, 0))
  108.         pixels.show()
  109.         time.sleep(.25)
  110.  
  111.         pixels.fill((0, 0, 255))
  112.         pixels.show()
  113.         time.sleep(.25)
  114.  
  115.         pixels.fill((255, 255, 255))
  116.         pixels.show()
  117.         time.sleep(.25)
  118.  
  119.     if rainbowDemo:
  120.         print('Rainbow Demo')
  121.         rainbow(.001)
  122.  
  123.     if rainbowCycleDemo:
  124.         print('Rainbow Cycle Demo')
  125.         rainbow_cycle(.001)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement