Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function splitString(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function newLine(amt)
- amt = amt or 1
- x, y = monitor.getCursorPos()
- monitor.setCursorPos(1, y+amt)
- end
- os.loadAPI("buttonAPI")
- --BUTTON API
- button = buttonAPI.new("back")
- button:add("ON", nil, 2, 7, 6, 9, colors.red, colors.lime)
- button:add("OFF", nil, 9, 7, 13, 9, colors.red, colors.lime)
- button:draw()
- --END
- ON, OFF = 15, 0
- rednet.open("right")
- monitor = peripheral.wrap("back")
- monitor.setTextScale(1)
- monitor.setBackgroundColor(colors.red)
- current, f, t, w = "NIL", "NIL", "NIL", "NIL"
- while true do
- repeat
- term.clear()
- print("ON=1/OFF=2")
- monitor.clear()
- button:draw()
- monitor.setCursorPos(1,1)
- monitor.write("CURRENT STATUS : " .. current); newLine()
- monitor.write("----------------------------"); newLine()
- monitor.write("FUEL : " .. f); newLine()
- monitor.write("TEMPERATURE : " .. t); newLine()
- monitor.write("WASTE : " .. w)
- event, p1, p2 = button:handleEvents(os.pullEvent())
- until
- event == "rednet_message" or
- (event == "char" and (p1 == "1" or p1 == "2")) or
- event == "button_click"
- if event == "char" then
- if p1 == "1" then
- rednet.broadcast("1")
- else
- rednet.broadcast("2")
- end
- elseif event == "rednet_message" then
- monitor.clear()
- button:draw()
- monitor.setCursorPos(1,1)
- split = splitString(p2, ";")
- current = split[1]
- f = split[2]
- t = split[3]
- w = split[4]
- if current == "OK" then current = "OFF" end
- monitor.write("CURRENT STATUS : " .. current); newLine()
- monitor.write("----------------------------"); newLine()
- monitor.write("FUEL : " .. f); newLine()
- monitor.write("TEMPERATURE : " .. t); newLine()
- monitor.write("WASTE : " .. w)
- else
- button:flash(p1)
- if p1 == "ON" then
- rednet.broadcast("1")
- else
- rednet.broadcast("2")
- end
- end
- end
Add Comment
Please, Sign In to add comment