Advertisement
DOGGYWOOF

GPS

Dec 30th, 2024 (edited)
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. -- Simple Position Display Program for Pocket Computer with Enhanced Design
  2.  
  3. -- Check if GPS is available
  4. if not gps then
  5. print("GPS is not available!")
  6. return
  7. end
  8.  
  9. -- Function to get current coordinates
  10. local function getCoordinates()
  11. local x, y, z = gps.locate()
  12. if not x then
  13. print("Failed to locate! Ensure GPS is available.")
  14. return nil
  15. end
  16. -- Subtract 2 from the Y axis to correct the offset (if needed)
  17. y = y - 2
  18. return x, y, z
  19. end
  20.  
  21. -- Function to display current position in a clean, centered layout
  22. local function displayPosition()
  23. local x, y, z = getCoordinates()
  24. if x then
  25. term.clear() -- Clear the screen
  26.  
  27. -- Set background and text color
  28. term.setBackgroundColor(colors.black)
  29. term.setTextColor(colors.white)
  30.  
  31. -- Display the title
  32. term.setCursorPos(1, 1)
  33. term.write("Current Position")
  34.  
  35. -- Add some space
  36. term.setCursorPos(1, 2)
  37. term.write("") -- Empty line for spacing
  38.  
  39. -- Display X, Y, Z coordinates
  40. term.setCursorPos(1, 3)
  41. term.setTextColor(colors.green)
  42. term.write("X: " .. x)
  43.  
  44. term.setCursorPos(1, 4)
  45. term.setTextColor(colors.green)
  46. term.write("Y: " .. y)
  47.  
  48. term.setCursorPos(1, 5)
  49. term.setTextColor(colors.green)
  50. term.write("Z: " .. z)
  51.  
  52. -- Make sure everything fits well and is spaced out
  53. term.setTextColor(colors.white) -- Reset text color for potential future use
  54. end
  55. end
  56.  
  57. -- Main loop to update the position
  58. while true do
  59. displayPosition()
  60. sleep(0.1) -- Update every 1 second
  61. end
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement