Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = peripheral.find("monitor")
- local side_bundle = ("front")
- local t = {
- purple = {
- desc = "Purple ",
- side = "right",
- flux_level = 0,
- flux_max = 7,
- output = colours.purple, -- used for bundle
- enderio_output = pink
- },
- lime = {
- desc = "Lime ",
- side = "bottom",
- flux_level = 0,
- flux_max = 7,
- output = colours.lime, --
- enderio_output = cyan
- },
- orange = {
- desc = "Orange ",
- side = "left",
- flux_level = 0,
- flux_max = 7,
- output = colours.orange, --
- enderio_output = yellow
- },
- brown = {
- desc = "Central",
- side = "top",
- flux_level = 0,
- flux_max = 5,
- output = colours.brown, --
- enderio_output = black
- }
- }
- ---------------------------
- --Rednet sender, receiver
- ---------------------------
- peripheral.find("modem",rednet.open)
- local function receiveTable()
- id, msg = rednet.receive()
- t = textutils.unserialise(msg)
- print("Rednet received")
- end
- ---------------------------
- --Monitor related stuff
- ---------------------------
- --term.redirect(m)
- local monitors = {peripheral.find("monitor")}
- m.setCursorPos(0,0)
- m.setBackgroundColor(colors.black)
- m.setTextColor(colors.white)
- m.clear()
- m.setTextScale(3)
- ----------------------------
- --Prints Table for debugging
- ----------------------------
- local function printTable(e)
- if type(e) == "table" then
- for k,v in pairs(e) do
- print(k,v)
- printTable(v) -- recursively repeat the same procedure
- sleep(2)
- end
- else
- end
- end
- ---------------------------
- --Updates table
- ---------------------------
- local function getUpdate()
- for k,v in pairs(t) do
- v.flux_level = rs.getAnalogInput(v.side)
- end
- end
- ---------------------------
- --Emits bundled redstone when flux max is exceeded
- ---------------------------
- local function stopProduction()
- for k,v in pairs(t) do
- sleep(0)
- if v.flux_level >= v.flux_max then
- rs.setBundledOutput(side_bundle,colours.combine(rs.getBundledOutput("front"),v.output))
- rs.setAnalogOutput(v.side,1)
- print("Stoped:", v.desc, v.flux_level)
- else
- sleep(0)
- rs.setBundledOutput(side_bundle,colours.subtract(rs.getBundledOutput("front"), v.output))
- rs.setAnalogOutput(v.side,0)
- print("Good")
- end
- end
- end
- ---------------------------
- --Visual table
- ---------------------------
- local w = 0
- local h = 0
- local function displayFlux()
- for k,v in pairs(t) do
- h = h + 1
- if h > 4 then h = 1 end
- m.setCursorPos(1,h)
- m.setBackgroundColor(v.output)
- m.write(v.desc)
- m.setBackgroundColor(colors.black)
- m.setCursorPos(8,h)
- if v.flux_level < v.flux_max * 0.5 then
- m.setBackgroundColor(colors.green)
- m.write(v.flux_level.."/"..v.flux_max)
- elseif v.flux_level < v.flux_max * 0.8 then
- m.setBackgroundColor(colors.yellow)
- m.write(v.flux_level.."/"..v.flux_max)
- else
- m.setBackgroundColor(colors.red)
- m.write(v.flux_level.."/"..v.flux_max)
- end
- end
- end
- ---------------------------
- --Starts the script
- ---------------------------
- local n = 0
- local function start()
- while true do
- n = n + 1
- print("--------------------------------")
- print("--------------------------------",n)
- receiveTable()
- displayFlux()
- end
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment