Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys
  3. from sense_hat import SenseHat
  4.  
  5. # To get good results with the magnetometer you must first calibrate it using
  6. # the program in RTIMULib/Linux/RTIMULibCal
  7. # The calibration program will produce the file RTIMULib.ini
  8. # Copy it into the same folder as your Python code
  9.  
  10. led_loop = [4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8, 0, 1, 2, 3]
  11.  
  12. sense = SenseHat()
  13. sense.set_rotation(0)
  14. sense.clear()
  15.  
  16. prev_x = 0
  17. prev_y = 0
  18.  
  19. led_degree_ratio = len(led_loop) / 360.0
  20.  
  21. while True:
  22. dir = sense.get_compass()
  23. dir_inverted = 360 - dir # So LED appears to follow North
  24. led_index = int(led_degree_ratio * dir_inverted)
  25. offset = led_loop[led_index]
  26.  
  27. y = offset // 8 # row
  28. x = offset % 8 # column
  29.  
  30. if x != prev_x or y != prev_y:
  31. sense.set_pixel(prev_x, prev_y, 0, 0, 0)
  32.  
  33. sense.set_pixel(x, y, 0, 0, 255)
  34.  
  35. prev_x = x
  36. prev_y = y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement