apa102_demo.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. from luma.led_matrix.device import apa102
  7. from luma.core.render import canvas
  8. device = apa102(width=8, height=1)
  9. def rotate(l):
  10. return l[-1:] + l[:-1]
  11. def main():
  12. colors = [
  13. "red",
  14. "orange",
  15. "yellow",
  16. "green",
  17. "blue",
  18. "indigo",
  19. "violet",
  20. "white"
  21. ]
  22. for color in colors:
  23. with canvas(device) as draw:
  24. draw.line(device.bounding_box, fill=color)
  25. time.sleep(2)
  26. device.contrast(0x30)
  27. for _ in range(80):
  28. with canvas(device) as draw:
  29. for x, color in enumerate(colors):
  30. draw.point((x, 0), fill=color)
  31. colors = rotate(colors)
  32. time.sleep(0.2)
  33. time.sleep(4)
  34. device.contrast(0x80)
  35. time.sleep(1)
  36. device.contrast(0x10)
  37. time.sleep(1)
  38. if __name__ == "__main__":
  39. try:
  40. main()
  41. except KeyboardInterrupt:
  42. pass