AsTio

Monitor Mekanism

Jun 20th, 2019
169
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. m = peripheral.wrap("left")
  2. modem = peripheral.wrap("right")
  3. wmodem = peripheral.wrap("back")
  4. status = 0
  5. -- -------------Wejście-----------------------------
  6. m.setCursorPos(6,7)
  7. m.setTextScale(2)
  8. m.setBackgroundColour(colors.black)
  9. m.setTextColour(colors.white)
  10. m.clear()
  11. m.write("Touch monitor to continue")
  12. os.pullEvent("monitor_touch")
  13. sleep(0.3)
  14. -- ----------------------------MENU-----------------------------------
  15. while true do
  16. m.clear()
  17. m.setCursorPos(1,1)
  18. m.setTextScale(1)
  19. -- -----------ASTIOMAT 3000-----------------
  20. win = window.create(m ,23,1,27,3)
  21. win.setBackgroundColour(colors.lightBlue)
  22. win.setTextColour(colors.red)
  23. win.clear()
  24. win.setCursorPos(8,2)
  25. win.write("ASTIOMAT 3000")
  26. -- ----------------1,-1b reserve---------------
  27. m.setCursorPos(15,6)
  28. m.setTextColour(colors.white)
  29. m.setTextScale(1)
  30. m.write("Floor -1 and -1b reserve evergy: ")
  31. m.setTextColour(colors.lightBlue)
  32. modem.open(57000)
  33. timeout = os.startTimer(0.15)
  34. while true do
  35.   event, s, f, rf, msg = os.pullEvent()
  36.     if event == "modem_message" then
  37.         if msg == "ON" then
  38.             m.write("[ACTIVE]")
  39.         end
  40.         if msg == "OFF" then
  41.             m.write("[INACTIVE]")
  42.         end
  43.         break
  44.     end
  45.  if event == "timer" then
  46.     m.write("[DISCONNECTED]")
  47.     m.setCursorPos(65,6)
  48.     m.write("[R]")
  49.     break
  50.  end
  51. end
  52. modem.close(57000)
  53. sleep(0.1)
  54. -- -----------3 lgihts-----------------
  55. m.setCursorPos(24,8)
  56. m.setTextColour(colors.white)
  57. m.write("Floor -3 lights: ")
  58. m.setTextColour(colors.lightBlue)
  59. wmodem.open(57002)
  60. timeout = os.startTimer(0.2)
  61. while true do
  62.   event, s, f, rf, msg = os.pullEvent()
  63.     if event == "modem_message" then
  64.         if msg == "ON" then
  65.             m.write("[ACTIVE]")
  66.             ls = 1
  67.         end
  68.         if msg == "OFF" then
  69.             m.write("[INACTIVE]")
  70.             ls = 0
  71.         end
  72.         if msg == "" then
  73.             m.write("[DISCONNECTED]")
  74.             m.setCursorPos(65,8)
  75.             m.write("[R]")
  76.             ls = 2
  77.         end
  78.         break
  79.     end
  80.  if event == "timer" then
  81.     m.write("[DISCONNECTED]")
  82.     m.setCursorPos(65,8)
  83.     m.write("[R]")
  84.     ls = 2
  85.     break
  86.  end
  87. end
  88. wmodem.close(57002)
  89. sleep(0.1)
  90. -- -------LOG OUT-------------
  91. m.setCursorPos(2,18)
  92. m.setTextColour(colors.lightBlue)
  93. m.setTextScale(1)
  94. m.write("log out")
  95. -- -----------WYBÓR---------------
  96. modem.open(55001)
  97. event, side, port, respPort, msg = os.pullEvent("modem_message")
  98. print("Pos x:" .. msg[1])
  99. print("Pos y:" .. msg[2])
  100.  -- -----------LOG OUT------------
  101. if tonumber(msg[1]) >= 1 and tonumber(msg[1]) <= 8 and tonumber(msg[2]) >= 17  and tonumber(msg[2]) <= 19 then
  102.         os.reboot()
  103. end
  104. -- ---------------3 LIGHTS--------
  105. if tonumber(msg[1]) >= 23 and tonumber(msg[1]) <= 48 and tonumber(msg[2]) >= 8  and tonumber(msg[2]) <= 9 then
  106.     if ls == 0 then
  107.         wmodem.transmit(55002, 1, "ON")
  108.     end
  109.     if ls == 1 then
  110.         wmodem.transmit(55002, 1, "OFF")
  111.     end
  112. end
  113. -- ----------------RECONNECT----------------
  114. if ls == 2 then
  115.     if tonumber(msg[1]) >= 65 and tonumber(msg[1]) <= 67 and tonumber(msg[2]) >= 8  and tonumber(msg[2]) <= 9 then
  116.         wmodem.transmit(55002, 1, "ON")
  117.     end
  118. end
  119. -- ----------------------------------------------
  120. win.setVisible(false)
  121. term.clear()
  122. term.setCursorPos(1,1)
  123. end
  124. -- -------------------FUNKCJE--------------------------------------------
  125. local function status0()
  126. if status == 0 then
  127.     m.setCursorPos(5,3)
  128.     m.setTextScale(4)
  129.     m.setBackgroundColour(colors.green)
  130.     m.setTextColour(colors.blue)
  131.     m.clear()
  132.     m.write("[INACTIVE]")
  133.     peripheral.call("back", "transmit", 55000, 1, "STOP")
  134. end
  135. end
  136. local function status1()
  137. if status == 1 then
  138.      m.setCursorPos(6,3)
  139.      m.setTextScale(4)
  140.      m.setTextColour(colors.blue)
  141.      m.setBackgroundColour(colors.red)
  142.      m.clear()
  143.      m.write("[ACTIVE]")
  144.     peripheral.call("back", "transmit", 55000, 1, "POWER")
  145. end
  146. end
  147. -- ---------------Funkcja Zapasowaj energi-------------------------
  148. local function reserv()
  149.     while true do
  150.         os.pullEvent("monitor_touch")
  151.         status = status + 1
  152.  
  153.         if status >= 2 then
  154.             status = 0
  155.         end
  156.         if status == 1 then
  157.             status1()
  158.         end
  159.         if status == 0 then
  160.             status0()
  161.         end
  162.     end
  163. end
  164. -- ----------------------------------------------------
RAW Paste Data