Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- BigReactors - Basic Reactor Control
- -- ----------------------------------------------------------
- -- Version 7.0 added button to control reactor
- -- Jerotire, Etari_be
- -- Based on code by Etari_be
- -- Initilisation function (run-once)
- function init()
- -- Wrap the reactor..
- reactor = peripheral.wrap("BigReactors-Reactor_3")
- mon = peripheral.wrap("monitor_12")
- -- Setup terminal..
- mon.clear()
- mon.setCursorPos(1,2)
- mon.write(" REACTOR CONTROL")
- mon.setCursorPos(1,3)
- mon.write(" -----------------------------")
- init_var = {}
- reactorData = {}
- --reactor_E_full = true
- reactor.setActive(true)
- end
- function init_monitor() -- put text on the monitor (is not gonna change while the program runs)
- init_var[1] = " Reactor Active : " -- text to type
- init_var[2] = " Fuel Temp : "
- init_var[3] = " Casing Temp : "
- init_var[4] = " Energy/Tick : "
- init_var[5] = " Fuelusage/Tick : "
- init_var[6] = " Total Fuel : "
- init_var[7] = " Total Waste : "
- init_var[8] = " Energy Stored : "
- init_var[9] = " ControlRods at : "
- for k = 1,9 do -- printing on the monitor
- mon.setCursorPos(1,k + 4)
- mon.write(init_var[k])
- end
- end
- function write_m(var, colum, row) -- print on the screen : var = msg, colum = vertical loc, row = what row to print on
- mon.setCursorPos(colum,row)
- mon.write(var)
- end
- function round(var)
- local roundvar = var*100
- roundvar = math.floor(roundvar + 0.5)
- roundvar = roundvar/100
- return roundvar
- end
- function Read_reactor()
- reactorData[1] = tostring(reactor.getActive()).." "
- reactorData[2] = round(reactor.getFuelTemperature())
- reactorData[3] = round(reactor.getCasingTemperature())
- reactorData[4] = round(reactor.getEnergyProducedLastTick())
- reactorData[5] = round(reactor.getFuelConsumedLastTick())
- reactorData[6] = reactor.getFuelAmount() /1000
- reactorData[7] = reactor.getWasteAmount()/1000
- reactorData[8] = reactor.getEnergyStored()
- end
- function reactorfull(E) -- check reactor stored energy
- reactor.setAllControlRodLevels(E/100000)
- write_m(tostring(E/100000),20,13)
- --if E > 9000000 then
- -- reactor.setActive(false) -- deactivate reactor so no fuel is lost
- -- reactor_E_full = true
- --elseif E < 2000000 then
- -- reactor.setActive(true) -- activate reactor when charge is below 9M energy
- -- reactor_E_full = false
- --end
- end
- function DrawButton(bolean)
- if bolean == false then
- mon.setBackgroundColor(colors.green)
- mon.setCursorPos(12,16)
- mon.write(" ")
- mon.setCursorPos(12,17)
- mon.write(" Activate ")
- mon.setCursorPos(12,18)
- mon.write(" ")
- else
- mon.setBackgroundColor(colors.red)
- mon.setCursorPos(12,16)
- mon.write(" ")
- mon.setCursorPos(12,17)
- mon.write(" Deactivate ")
- mon.setCursorPos(12,18)
- mon.write(" ")
- end
- mon.setBackgroundColor(colors.black)
- end
- function button()
- event, event_mon, xPos, yPos = os.pullEvent("monitor_touch")
- print(event,event_mon,xPos,yPos)
- if (event_mon == "monitor_12" and (xPos > 12 and xPos < 24) and (yPos > 15 and yPos < 19)) then
- reactor.setActive(not(reactor.getActive()))
- DrawButton(reactor.getActive())
- print("screenhit at "..xPos.." "..yPos)
- end
- end
- ------------------------------------------------
- --actual program start--
- ------------------------------------------------
- init()
- init_monitor()
- DrawButton(true)
- function autonomus()
- -- sleep(0) -- so the program will not crash
- Read_reactor() -- get values from reactor
- --data = textutils.unserialize(data_m)
- for x = 1, 8 do
- mon.setCursorPos(20,x + 4)
- mon.write(reactorData[x])
- end
- -- write_m(data.Reactoractief.." ",18,1)
- -- write_m(data.Fueltemp,18,2)
- -- write_m(data.Casingtemp,18,3)
- -- write_m(data.EnergyTick.." ",18,4)
- -- write_m(data.FuelTick.." ",18,5)
- -- write_m(data.FuelTotal,18,6)
- -- write_m(data.WasteTotal,18,7)
- -- write_m(data.Energy.." ",18,8)
- reactorfull(reactorData[8])
- sleep(0.5)
- end
- while true do
- parallel.waitForAny(autonomus,button)
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement