led.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import sys
  2. import time
  3. from neopixel import *
  4. # LED strip configuration:
  5. LED_COUNT = 66 # Number of LED pixels.
  6. LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
  7. LED_FREQ_HZ = 700000 # LED signal frequency in hertz (usually 800khz)
  8. LED_DMA = 5 # DMA channel to use for generating signal (try 5)
  9. LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
  10. LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
  11. def setLed(strip, l,r,g,b):
  12. strip.setPixelColor(l,Color(r,g,b))
  13. def strobetest(strip):
  14. on = True
  15. while True:
  16. if on:
  17. on = False
  18. for i in range(strip.numPixels()):
  19. strip.setPixelColor(i, Color(255,255,255))
  20. else:
  21. on = True
  22. for i in range(strip.numPixels()):
  23. strip.setPixelColor(i, Color(0,0,0))
  24. strip.show()
  25. time.sleep(100.0/1000)
  26. if __name__ == '__main__':
  27. ledstrip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
  28. ledstrip.begin()
  29. s = sys.stdin.readline().strip()
  30. while s not in ['break', 'quit']:
  31. message = s.split("|")
  32. returnms = 'e'
  33. if(message[0] == '1'):
  34. if (len(message) == 5):
  35. try:
  36. led = int(message[1])
  37. r = int(message[2])
  38. g = int(message[3])
  39. b = int(message[4])
  40. setLed(ledstrip, led,r,g,b)
  41. returnms = 'a'
  42. except ValueError:
  43. returnms = 'e'
  44. elif (message[0] == '0'):
  45. ledstrip.show()
  46. returnms = 'a'
  47. s = sys.stdin.readline().strip()