Guest User

Untitled

a guest
Mar 19th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import machine
  2. import neopixel
  3. import time
  4. import framebuf as fb
  5.  
  6. NR_PIXEL_WIDTH = const(8)
  7. NR_PIXEL_HEIGHT = const(8)
  8. buf_array = bytearray(NR_PIXEL_WIDTH * NR_PIXEL_HEIGHT * 3)
  9.  
  10. p1 = machine.Pin(13,machine.Pin.OUT)
  11. fbuf = fb.FrameBuffer(buf_array, NR_PIXEL_WIDTH, NR_PIXEL_HEIGHT, fb.RGB888)
  12.  
  13. @micropython.viper
  14. def zickzack_rgb24(fbuf):
  15. buf = ptr8(fbuf)
  16. for y in range(0, NR_PIXEL_HEIGHT, 2):
  17. offset_s = NR_PIXEL_WIDTH * y * 3
  18. offset_e = offset_s + 3 * (NR_PIXEL_WIDTH - 1)
  19. # print("{} - {}".format(offset_s, offset_e))
  20. for x in range(0, NR_PIXEL_WIDTH//2):
  21. tmp = buf[offset_e - x * 3]
  22. buf[offset_e - x * 3] = buf[offset_s + x * 3]
  23. buf[offset_s + x * 3] = tmp
  24. tmp = buf[offset_e - x * 3 +1]
  25. buf[offset_e-x * 3 + 1] = buf[offset_s + x * 3 +1]
  26. buf[offset_s+x * 3 + 1] = tmp
  27. tmp = buf[offset_e - x * 3 +2]
  28. buf[offset_e - x * 3 + 2] = buf[offset_s + x * 3 + 2]
  29. buf[offset_s+x * 3 + 2] = tmp
  30.  
  31. def write_neo(text):
  32. fbuf.fill(0)
  33. for c in text:
  34. fbuf.text(c, 0, 0, 10)
  35. zickzack_rgb24(buf_array)
  36. neopixel.neopixel_write(p1, buf_array, 1)
  37. time.sleep(1)
  38. fbuf.fill(0)
  39.  
  40. write_neo("HALLO")
Add Comment
Please, Sign In to add comment