Guest User

Untitled

a guest
Oct 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. ### This is the script powering trisight halloween costume, running on Adafruit GEMMA M0 running CircuitPython
  2. import board
  3. import neopixel
  4. import time
  5. try:
  6. import urandom as random # for v1.0 API support
  7. except ImportError:
  8. import random
  9.  
  10. # numpix = 17 # Number of NeoPixels
  11. numpix = 21 # Number of NeoPixels
  12. pixpin = board.D1 # Pin where NeoPixels are connected
  13. strip = neopixel.NeoPixel(pixpin, numpix)
  14.  
  15. minAlpha = 0.1 # Minimum brightness
  16. maxAlpha = 0.1 # Maximum brightness
  17. alpha = (minAlpha + maxAlpha) / 2 # Start in middle
  18. alphaDelta = 0.0008 # Amount to change brightness each time through loop
  19. alphaUp = True # If True, brightness increasing, else decreasing
  20.  
  21. def wheel(pos):
  22. """Generate rainbow colors across 0-255 positions. In the order of r-g-b"""
  23. if pos < 85:
  24. return [255 - pos * 3, pos * 3, 0]
  25. elif pos < 170:
  26. pos -= 85
  27. return [0, 255 - pos * 3, pos * 3]
  28. else:
  29. pos -= 170
  30. return [pos * 3, 0, 255 - pos * 3]
  31.  
  32. # strip.fill([80, 0, 255]) # Fill red, or change to R,G,B of your liking
  33. pos = 0
  34. # for i in range(len(strip)):
  35. # strip[i] = wheel(pos % 255)
  36. # pos += 20
  37.  
  38. while True: # Loop forever...
  39. if random.randint(1, 5) == 5: # 1-in-5 random chance
  40. alphaUp = not alphaUp # of reversing direction
  41. if alphaUp: # Increasing brightness?
  42. alpha += alphaDelta # Add some amount
  43. if alpha >= maxAlpha: # At or above max?
  44. alpha = maxAlpha # Limit to max
  45. alphaUp = False # and switch direction
  46. else: # Else decreasing brightness
  47. alpha -= alphaDelta # Subtract some amount
  48. if alpha <= minAlpha: # At or below min?
  49. alpha = minAlpha # Limit to min
  50. alphaUp = True # and switch direction
  51.  
  52. pos += 1
  53. strip.fill(wheel(pos % 255))
  54. strip.brightness = alpha # Set brightness to 0.0 to 1.0
  55. strip.write() # and issue data to LED strip
Add Comment
Please, Sign In to add comment