Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Monitors energy levels on the left side.
- --Outputs generator control signal on the back.
- --Sends tank procentage with command "tankUpdate".
- local r = component.proxy(component.list("redstone")());
- local m = component.proxy(component.list("modem")());
- local t = component.proxy(component.list("tank_controller")());
- local port = 8000;
- local address = "lol";
- function sleep(time)
- local t = computer.uptime();
- while(computer.uptime() - t <= time) do
- computer.pushSignal("wait");
- computer.pullSignal();
- end
- end
- function beep()
- computer.beep();
- end
- function errorBeep()
- computer.beep(1000, 0.2);
- sleep(0.2);
- computer.beep(1000, 0.8);
- end
- function init()
- if(m) then
- if(r) then
- local portOpen = false;
- if(m.isOpen(port)) then
- portOpen = true;
- else
- portOpen = m.open(port);
- end
- if(portOpen) then
- beep();
- return true;
- end
- end
- end
- errorBeep();
- return false;
- end
- function getTankInfo()
- local cap = 0;
- local amount = 0;
- for i = 0, 5, 1 do
- local data = t.getFluidInTank(i);
- if(data ~= nil) then
- cap = tonumber(data[1]["capacity"]);
- amount = tonumber(data[1]["amount"]);
- end
- end
- local info = {};
- info["max"] = cap;
- info["amount"] = amount;
- return info;
- end
- --Main loop.
- if(init()) then
- while(true) do
- sleep(10);
- --Check state of energy cell.
- if(r.getInput(5) < 15) then
- --Energy cell is not fully charged.
- r.setOutput(2, 15);
- else
- --Energy cell is fully charged.
- r.setOutput(2, 0);
- end
- --Check lava levels and send it to the mainframe.
- local info = getTankInfo();
- local procentage = math.floor((info["amount"] / info["max"]) * 100);
- m.send(address, port, "tankUpdate", procentage);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement