Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Simple Position Display Program for Pocket Computer with Enhanced Design
- -- Check if GPS is available
- if not gps then
- print("GPS is not available!")
- return
- end
- -- Function to get current coordinates
- local function getCoordinates()
- local x, y, z = gps.locate()
- if not x then
- print("Failed to locate! Ensure GPS is available.")
- return nil
- end
- -- Subtract 2 from the Y axis to correct the offset (if needed)
- y = y - 2
- return x, y, z
- end
- -- Function to display current position in a clean, centered layout
- local function displayPosition()
- local x, y, z = getCoordinates()
- if x then
- term.clear() -- Clear the screen
- -- Set background and text color
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- -- Display the title
- term.setCursorPos(1, 1)
- term.write("Current Position")
- -- Add some space
- term.setCursorPos(1, 2)
- term.write("") -- Empty line for spacing
- -- Display X, Y, Z coordinates
- term.setCursorPos(1, 3)
- term.setTextColor(colors.green)
- term.write("X: " .. x)
- term.setCursorPos(1, 4)
- term.setTextColor(colors.green)
- term.write("Y: " .. y)
- term.setCursorPos(1, 5)
- term.setTextColor(colors.green)
- term.write("Z: " .. z)
- -- Make sure everything fits well and is spaced out
- term.setTextColor(colors.white) -- Reset text color for potential future use
- end
- end
- -- Main loop to update the position
- while true do
- displayPosition()
- sleep(0.1) -- Update every 1 second
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement