Advertisement
gbrnt

Location display

Nov 27th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. -- Code for computer which displays destinations
  2.  
  3. display_receive_channel = 4
  4.  
  5. -- Start peripherals
  6. display = peripheral.wrap("left")
  7. modem = peripheral.wrap("bottom")
  8. modem.open(display_receive_channel)
  9.  
  10. function clear_print(text)
  11.     y_size, x_size = display.getSize()
  12.     x_pos = (x_size - string.len(text)) / 2 + 6
  13.     y_pos = y_size / 2 - 5
  14.     --print(x_size.." "..y_size.." "..x_pos.." "..y_pos)
  15.     print(text)
  16.  
  17.     display.clear()
  18.     display.setCursorPos(x_pos, y_pos)
  19.     display.write(text)
  20. end
  21.  
  22. last_pressed = 0
  23.  
  24. while true do
  25.     local event, modemSide, senderChannel, replyChannel,
  26.         message, senderDistance = os.pullEvent("modem_message")
  27.  
  28.     last_pressed = tonumber(message)
  29.  
  30.     if     last_pressed == 0 then clear_print("No Destination")
  31.     elseif last_pressed == 1 then clear_print("Sacred Oak")
  32.     elseif last_pressed == 2 then clear_print("Redwood")
  33.     elseif last_pressed == 3 then clear_print("Destination 3")
  34.     elseif last_pressed == 4 then clear_print("Destination 4")
  35.     end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement