neosegment_demo.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (c) 2017-18 Richard Hull and contributors
  4. # See LICENSE.rst for details.
  5. import time
  6. import random
  7. import colorsys
  8. from luma.led_matrix.device import neosegment
  9. from neopixel_demo import gfx
  10. def rainbow(n=1000, saturation=1, value=1):
  11. """
  12. A generator that yields 'n' hues from the rainbow in the hex format #RRGGBB.
  13. By default the saturation and value (from HSV) are both set to 1.
  14. """
  15. for i in range(n):
  16. hue = i / float(n)
  17. color = [int(x * 255) for x in colorsys.hsv_to_rgb(hue, saturation, value)]
  18. yield ("#%02x%02x%02x" % tuple(color)).upper()
  19. def main():
  20. neoseg = neosegment(width=6)
  21. neoseg.text = "NEOSEG"
  22. time.sleep(1)
  23. neoseg.color[0] = "yellow"
  24. time.sleep(1)
  25. neoseg.color[3:5] = ["blue", "orange"]
  26. time.sleep(1)
  27. neoseg.color = "white"
  28. time.sleep(1)
  29. for _ in range(10):
  30. neoseg.device.hide()
  31. time.sleep(0.1)
  32. neoseg.device.show()
  33. time.sleep(0.1)
  34. time.sleep(1)
  35. for color in rainbow(200):
  36. neoseg.color = color
  37. time.sleep(0.01)
  38. colors = list(rainbow(neoseg.device.width))
  39. for _ in range(50):
  40. random.shuffle(colors)
  41. neoseg.color = colors
  42. time.sleep(0.1)
  43. neoseg.color = "white"
  44. time.sleep(3)
  45. for _ in range(3):
  46. for intensity in range(16):
  47. neoseg.device.contrast((15 - intensity) * 16)
  48. time.sleep(0.1)
  49. for intensity in range(16):
  50. neoseg.device.contrast(intensity * 16)
  51. time.sleep(0.1)
  52. neoseg.text = ""
  53. neoseg.device.contrast(0x80)
  54. time.sleep(1)
  55. neoseg.text = "rgb"
  56. time.sleep(1)
  57. neoseg.color[0] = "red"
  58. time.sleep(1)
  59. neoseg.color[1] = "green"
  60. time.sleep(1)
  61. neoseg.color[2] = "blue"
  62. time.sleep(5)
  63. for _ in range(3):
  64. for intensity in range(16):
  65. neoseg.device.contrast(intensity * 16)
  66. time.sleep(0.1)
  67. neoseg.text = ""
  68. neoseg.device.contrast(0x80)
  69. time.sleep(1)
  70. gfx(neoseg.device)
  71. if __name__ == "__main__":
  72. try:
  73. main()
  74. except KeyboardInterrupt:
  75. pass