Advertisement
assarbertil

pocket_computer.lua

Jan 18th, 2022
780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local ELEVATOR_1_TRANSMIT_CHANNEL = 555
  2. local ELEVATOR_1_REPLY_CHANNEL = 550
  3. local ELEVATOR_2_TRANSMIT_CHANNEL = 556
  4. local ELEVATOR_2_REPLY_CHANNEL = 551
  5.  
  6. term.clear()
  7.  
  8. local modem = peripheral.find("modem") or error("No modem attached", 0)
  9.  
  10.  
  11.  
  12. term.setCursorPos(17, 5)
  13. term.write("H-1")
  14.  
  15. local elevator_1_up = window.create(term.current(), 16, 6, 5, 3)
  16. elevator_1_up.setBackgroundColour(colors.blue)
  17. elevator_1_up.setTextColour(colors.white)
  18. elevator_1_up.clear()
  19. elevator_1_up.setCursorPos(3, 2)
  20. elevator_1_up.write("\24")
  21.  
  22. local elevator_1_stop = window.create(term.current(), 16, 9, 5, 3)
  23. elevator_1_stop.setBackgroundColour(colors.red)
  24. elevator_1_stop.setTextColour(colors.white)
  25. elevator_1_stop.clear()
  26. elevator_1_stop.setCursorPos(3, 2)
  27. elevator_1_stop.write("x")
  28.  
  29. local elevator_1_down = window.create(term.current(), 16, 12, 5, 3)
  30. elevator_1_down.setBackgroundColour(colors.blue)
  31. elevator_1_down.setTextColour(colors.white)
  32. elevator_1_down.clear()
  33. elevator_1_down.setCursorPos(3, 2)
  34. elevator_1_down.write("\25")
  35.  
  36.  
  37.  
  38. term.setCursorPos(23, 5)
  39. term.write("H-2")
  40.  
  41. local elevator_2_up = window.create(term.current(), 22, 6, 5, 3)
  42. elevator_2_up.setBackgroundColour(colors.blue)
  43. elevator_2_up.setTextColour(colors.white)
  44. elevator_2_up.clear()
  45. elevator_2_up.setCursorPos(3, 2)
  46. elevator_2_up.write("\24")
  47.  
  48. local elevator_2_stop = window.create(term.current(), 22, 9, 5, 3)
  49. elevator_2_stop.setBackgroundColour(colors.red)
  50. elevator_2_stop.setTextColour(colors.white)
  51. elevator_2_stop.clear()
  52. elevator_2_stop.setCursorPos(3, 2)
  53. elevator_2_stop.write("x")
  54.  
  55. local elevator_2_down = window.create(term.current(), 22, 12, 5, 3)
  56. elevator_2_down.setBackgroundColour(colors.blue)
  57. elevator_2_down.setTextColour(colors.white)
  58. elevator_2_down.clear()
  59. elevator_2_down.setCursorPos(3, 2)
  60. elevator_2_down.write("\25")
  61.  
  62.  
  63.  
  64. CurrentFloor = 1
  65.  
  66. house_overview = window.create(term.current(), 1, 2, 5, 18)
  67. house_overview.setBackgroundColour(colors.blue)
  68. house_overview.setTextColour(colors.white)
  69. house_overview.clear()
  70. -- house_overview.setCursorPos(5, 18)
  71. -- house_overview.setCursorPos(1, 18)
  72. -- house_overview.write(currentFloor)
  73.  
  74.  
  75.  
  76. local test_button = window.create(term.current(), 7, 18, 3, 3)
  77. test_button.setBackgroundColour(colors.green)
  78. test_button.setTextColour(colors.white)
  79. test_button.clear()
  80. test_button.setCursorPos(2, 2)
  81. test_button.write("!")
  82.  
  83.  
  84. -- Main program loop
  85. while true do
  86.  
  87.   CurrentFloor = CurrentFloor + 1
  88.  
  89.   house_overview.clear()
  90.   house_overview.setCursorPos(1, 18)
  91.   house_overview.write(CurrentFloor)
  92.  
  93.   local event, button, x, y = os.pullEvent("mouse_click")
  94.  
  95.  
  96.  
  97.   --Elevator 1
  98.   if ((x >= 16 and x <= 20) and (y >= 6 and y <= 8)) then
  99.     modem.transmit(ELEVATOR_1_TRANSMIT_CHANNEL, ELEVATOR_1_REPLY_CHANNEL, "up")
  100.  
  101.   elseif ((x >= 16 and x <= 20) and (y >= 9 and y <= 11)) then
  102.     modem.transmit(ELEVATOR_1_TRANSMIT_CHANNEL, ELEVATOR_1_REPLY_CHANNEL, "stop")
  103.  
  104.   elseif ((x >= 16 and x <= 20) and (y >= 12 and y <= 14)) then
  105.     modem.transmit(ELEVATOR_1_TRANSMIT_CHANNEL, ELEVATOR_1_REPLY_CHANNEL, "down")
  106.   end
  107.  
  108.  
  109.  
  110.   --Elevator 2
  111.   if ((x >= 22 and x <= 26) and (y >= 6 and y <= 8)) then
  112.     modem.transmit(ELEVATOR_2_TRANSMIT_CHANNEL, ELEVATOR_2_REPLY_CHANNEL, "up")
  113.     term.setCursorPos(1,1)
  114.     term.write("Upp")
  115.  
  116.   elseif ((x >= 22 and x <= 26) and (y >= 9 and y <= 11)) then
  117.     modem.transmit(ELEVATOR_2_TRANSMIT_CHANNEL, ELEVATOR_2_REPLY_CHANNEL, "stop")
  118.     term.setCursorPos(1,1)
  119.     term.write("Stopp")
  120.  
  121.   elseif ((x >= 22 and x <= 26) and (y >= 12 and y <= 14)) then
  122.     modem.transmit(ELEVATOR_2_TRANSMIT_CHANNEL, ELEVATOR_2_REPLY_CHANNEL, "down")
  123.     term.setCursorPos(1,1)
  124.     term.write("Ner")
  125.   end
  126.  
  127.  
  128.  
  129.   --Test Button
  130.   if ((x >= 7 and x <= 8) and (y >= 18 and y <= 20)) then
  131.     modem.transmit(ELEVATOR_2_TRANSMIT_CHANNEL, ELEVATOR_2_REPLY_CHANNEL, 1)
  132.     term.setCursorPos(1,1)
  133.     term.write("Upp 1 vn")
  134.   end
  135.  
  136.  
  137.  
  138. end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement