Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import board
  2. import busio
  3. import neopixel
  4. from time import sleep
  5. from adafruit_circuitplayground.express import cpx
  6. pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.01)
  7. uart = busio.UART(board.TX, board.RX, baudrate=115200)
  8. data = uart.read(2)
  9. cpx.red_led = True
  10. sleep(.5)
  11. cpx.red_led = False
  12. pixels[1] = (255, 255, 0)
  13.  
  14. while True:
  15. data = uart.read(2)
  16. cpx.red_led = True
  17. sleep(.5)
  18. cpx.red_led = False
  19. sleep(.1)
  20. if data is not None:
  21. data_string = ''.join([chr(b) for b in data])
  22. # print(data_string, end="")
  23.  
  24. count = int(data_string)
  25. if count <= 9:
  26. cpx.red_led = True
  27. for x in range(count):
  28. pixels[x] = (255, 0, 0)
  29. sleep(.05)
  30. pixels[count] = (0, 255, 0)
  31. cpx.red_led = False
  32. else:
  33. cpx.red_led = True
  34. sleep(.1)
  35. cpx.red_led = False
  36. sleep(.1)
  37. cpx.red_led = True
  38. for x in range(count % 10):
  39. pixels[x] = (255, 0, 0)
  40. sleep(.05)
  41. pixels[count % 10] = (0, 0, 255)
  42. count = count % 10
  43. cpx.red_led = False
  44. for x in range(count - 1, -1, -1):
  45. pixels[x] = (0, 0, 0)
  46. sleep(.05)
  47. sleep(.75)
  48. pixels.fill((0, 0, 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement