Muhi98

Master

Apr 14th, 2021 (edited)
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.34 KB | None | 0 0
  1. function splitString(inputstr, sep)
  2.     if sep == nil then
  3.         sep = "%s"
  4.     end
  5.     local t={}
  6.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  7.             table.insert(t, str)
  8.     end
  9.     return t
  10. end
  11.  
  12. function newLine(amt)
  13.     amt = amt or 1
  14.  
  15.     x, y = monitor.getCursorPos()
  16.     monitor.setCursorPos(1, y+amt)
  17. end
  18.  
  19. os.loadAPI("buttonAPI")
  20.  
  21. --BUTTON API
  22. button = buttonAPI.new("back")
  23. button:add("ON", nil, 2, 7, 6, 9, colors.red, colors.lime)
  24. button:add("OFF", nil, 9, 7, 13, 9, colors.red, colors.lime)
  25. button:draw()
  26. --END
  27.  
  28. ON, OFF = 15, 0
  29. rednet.open("right")
  30. monitor = peripheral.wrap("back")
  31. monitor.setTextScale(1)
  32. monitor.setBackgroundColor(colors.red)
  33.  
  34.  
  35. current, f, t, w = "NIL", "NIL", "NIL", "NIL"
  36.  
  37.  
  38.  
  39. while true do
  40.     repeat
  41.         term.clear()
  42.         print("ON=1/OFF=2")
  43.  
  44.         monitor.clear()
  45.         button:draw()
  46.         monitor.setCursorPos(1,1)
  47.  
  48.  
  49.         monitor.write("CURRENT STATUS   : " .. current); newLine()
  50.         monitor.write("----------------------------"); newLine()
  51.         monitor.write("FUEL             : " .. f); newLine()
  52.         monitor.write("TEMPERATURE      : " .. t); newLine()
  53.         monitor.write("WASTE            : " .. w)
  54.  
  55.  
  56.         event, p1, p2 = button:handleEvents(os.pullEvent())
  57.     until
  58.     event == "rednet_message" or
  59.     (event == "char" and (p1 == "1" or p1 == "2")) or
  60.     event == "button_click"
  61.    
  62.     if event == "char" then
  63.         if p1 == "1" then
  64.             rednet.broadcast("1")
  65.         else
  66.             rednet.broadcast("2")
  67.         end
  68.     elseif event == "rednet_message" then
  69.         monitor.clear()
  70.         button:draw()
  71.         monitor.setCursorPos(1,1)
  72.         split = splitString(p2, ";")
  73.         current = split[1]
  74.         f = split[2]
  75.         t = split[3]
  76.         w = split[4]
  77.         if current == "OK" then current = "OFF" end
  78.  
  79.         monitor.write("CURRENT STATUS   : " .. current); newLine()
  80.         monitor.write("----------------------------"); newLine()
  81.         monitor.write("FUEL             : " .. f); newLine()
  82.         monitor.write("TEMPERATURE      : " .. t); newLine()
  83.         monitor.write("WASTE            : " .. w)
  84.  
  85.     else
  86.         button:flash(p1)
  87.         if p1 == "ON" then
  88.             rednet.broadcast("1")
  89.         else
  90.             rednet.broadcast("2")
  91.         end
  92.     end
  93. end
Add Comment
Please, Sign In to add comment