Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # NeoPixel library strandtest example
  3. # Author: Tony DiCola (tony@tonydicola.com)
  4. #
  5. # Direct port of the Arduino NeoPixel library strandtest example. Showcases
  6. # various animations on a strip of NeoPixels.
  7.  
  8. import time
  9. from neopixel import *
  10. import argparse
  11.  
  12. # LED strip configuration:
  13. LED_COUNT = 16 # Number of LED pixels.
  14. LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
  15. #LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
  16. LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
  17. LED_DMA = 10 # DMA channel to use for generating signal (try 10)
  18. LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
  19. LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
  20. LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
  21.  
  22.  
  23.  
  24. # Define functions which animate LEDs in various ways.
  25. def colorWipe(strip, color, wait_ms=50):
  26. """Wipe color across display a pixel at a time."""
  27. for i in range(strip.numPixels()):
  28. strip.setPixelColor(i, color)
  29. strip.show()
  30. time.sleep(wait_ms/1000.0)
  31.  
  32. # Main program logic follows:
  33. if __name__ == '__main__':
  34. # Process arguments
  35. parser = argparse.ArgumentParser()
  36. parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
  37. args = parser.parse_args()
  38.  
  39. # Create NeoPixel object with appropriate configuration.
  40. strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
  41. # Intialize the library (must be called once before other functions).
  42. strip.begin()
  43.  
  44. print ('Press Ctrl-C to quit.')
  45. if not args.clear:
  46. print('Use "-c" argument to clear LEDs on exit')
  47.  
  48. try:
  49.  
  50. while True:
  51. print ('Color wipe animations.')
  52. colorWipe(strip, Color(255, 0, 0)) # Red wipe
  53. colorWipe(strip, Color(255, 128, 0)) # Orange wipe
  54. colorWipe(strip, Color(204, 204, 0)) # Yellow wipe
  55. colorWipe(strip, Color(0, 204, 0)) # Green wipe
  56. colorWipe(strip, Color(255, 255, 0)) # Cyan wipe
  57. colorWipe(strip, Color(0, 255, 0)) # Blue wipe
  58. colorWipe(strip, Color(127, 0, 255)) # Green wipe
  59. colorWipe(strip, Color(255, 0, 127)) # Green wipe
  60.  
  61. except KeyboardInterrupt:
  62. if args.clear:
  63. colorWipe(strip, Color(0,0,0), 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement