Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. import time
  2. import board
  3. import neopixel
  4.  
  5.  
  6. # On CircuitPlayground Express, and boards with built in status NeoPixel -> board.NEOPIXEL
  7. # Otherwise choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D1
  8. pixel_pin = board.NEOPIXEL
  9.  
  10. # On a Raspberry pi, use this instead, not all pins are supported
  11. #pixel_pin = board.D18
  12.  
  13. # The number of NeoPixels
  14. num_pixels = 10
  15.  
  16. # The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
  17. # For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
  18. ORDER = neopixel.GRB
  19.  
  20. pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.1, auto_write=False,
  21. pixel_order=ORDER)
  22.  
  23.  
  24. def wheel(pos):
  25. # Input a value 0 to 255 to get a color value.
  26. # The colours are a transition r - g - b - back to r.
  27. if pos < 0 or pos > 255:
  28. r = g = b = 0
  29. elif pos < 85:
  30. r = int(pos * 3)
  31. g = int(255 - pos*3)
  32. b = 0
  33. elif pos < 170:
  34. pos -= 85
  35. r = int(255 - pos*3)
  36. g = 0
  37. b = int(pos*3)
  38. else:
  39. pos -= 170
  40. r = 0
  41. g = int(pos*3)
  42. b = int(255 - pos*3)
  43. return (r, g, b) if ORDER == neopixel.RGB or ORDER == neopixel.GRB else (r, g, b, 0)
  44.  
  45.  
  46. def rainbow_cycle(wait):
  47. for j in range(255):
  48. for i in range(num_pixels):
  49. pixel_index = (i * 256 // num_pixels) + j
  50. pixels[i] = wheel(pixel_index & 255)
  51. pixels.show()
  52. time.sleep(wait)
  53.  
  54.  
  55. while True:
  56. # Comment this line out if you have RGBW/GRBW NeoPixels
  57. # pixels.fill((255, 0, 0))
  58. # Uncomment this line if you have RGBW/GRBW NeoPixels
  59. # pixels.fill((255, 0, 0, 0))
  60. # pixels.show()
  61. # time.sleep(1)
  62.  
  63. # Comment this line out if you have RGBW/GRBW NeoPixels
  64. # pixels.fill((0, 255, 0))
  65. # Uncomment this line if you have RGBW/GRBW NeoPixels
  66. # pixels.fill((0, 255, 0, 0))
  67. # pixels.show()
  68. # time.sleep(1)
  69.  
  70. # Comment this line out if you have RGBW/GRBW NeoPixels
  71. # pixels.fill((0, 0, 255))
  72. # Uncomment this line if you have RGBW/GRBW NeoPixels
  73. # pixels.fill((0, 0, 255, 0))
  74. # pixels.show()
  75. # time.sleep(1)
  76.  
  77. rainbow_cycle(0.0001) # rainbow cycle with 1ms delay per step
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement