Youtube movie:
[media]http://www.youtube.com/watch?v=jZfUoa9Q5Zo&context=C486e0b0ADvjVQa1PpcFOzTJ1egzEUdRi3_72-k4pDQBwAjvq9pjM=[/media]
Code:
Spoiler
– Code by mrrg–
– Make sure reactor is OFF! controlled by red wire
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
– Make sure rin is initialized
rin=rs.getBundledInput("bottom")
term.clear()
term.setCursorPos(1,1)
print("======IRON NOVA REACTOR CONTROL SYSTEM V0.1======")
print("=================================================")
local sides=redstone.getSides()
print("=========== Scanning for pheripherals ===========")
print("")
for i=1,#sides do
if(peripheral.isPresent(sides)) then
local type=peripheral.getType(sides)
print("Found a "..type.." on the "..sides.."side.")
if(type=="SensorController") then
side = sides
local all_sens = sensors.getSensors(sides)
for i=1,#all_sens do
if(all_sens=="Reactor") then
sensor=all_sens
else
print("Reactor sensor not found!")
end
end
print(" Sensor name: "..sensor)
end
end
end
ok=false
print("")
print("=========== Analyzing reactor sensors ===========")
sensorInfo = sensors.getSensorInfo(side,sensor,"cardType","name","distance","SensorRange","loc","activereading")
print("Name: "..sensorInfo.name)
print("Type: "..sensorInfo.cardType)
–print("Distance: "..sensorInfo.distance)
–print("Range: "..sensorInfo.SensorRange)
targets = sensors.getAvailableTargets(side,sensor)
for i=1,#targets do
target=targets
local status = sensors.setTarget(side,sensor,target)
print(" Found "..#targets.." sensor target/targets.")
if(status) then
readings=sensors.getAvailableReadings(side,sensor)
for i=1,#readings do
–print("Readings: "..readings)
if(readings=="Reactor") then
print(" Found a reactor core.")
local status = sensors.setActiveReading(side,sensor,"Reactor")
if(status) then
if sensorInfo.cardType == "IndustrialCraft2 SensorModule" then
core = sensors.getReadingAsTable(side, sensor,"heat","maxheat","output","chambers")
print(" Accessing core readings ok.")
ok=true;
else
core = sensors.getReadingAsTable(side,sensor)
end
end
end
end
end
end
– Make sure reactor is OFF! controlled by red wire
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
–If we can read the reactor core with ic2 sensor module then go on
if(ok) then
print("")
print("Press P to power up reactor")
shutdown=true
cool_in_transit=0
cool_detect=false
request_cool_cnt=0
mon = peripheral.wrap('right')
mon.setTextScale(1)
mon.clear()
mon.setCursorPos(1,1)
mon.write(" IRON NOVA REACTOR")
mon.setCursorPos(1,2)
mon.write(" CONTROL SYSTEM V0.1")
while true do
event,arg = os.pullEvent()
– Update redstone input
if(event == "redstone") then
rin=rs.getBundledInput("bottom")
end
– Handle keys
if(event == "key") then
– print(arg)
if(arg==25) then – Start reactor
os.startTimer(1)
shutdown=false
term.clear()
term.setCursorPos(1,1)
end
if(arg==31) then – Shutdown reactor
shutdown=true
end
end
– Handle timer event, control the reactor
if(event=="timer") then
sensors.setActiveReading(side,sensor,"Reactor")
core = sensors.getReadingAsTable(side, sensor,"heat","maxheat","output","chambers")
term.clear()
term.setCursorPos(1,1)
heat = core[2]
power = core[6]
print("======IRON NOVA REACTOR CONTROL SYSTEM V0.1======")
if(colors.test(rout,colors.red)) then
print("Reactor is : OFFLINE")
else
print("Rector is : ONLINE")
end
print("Temperature : "..heat.." deg C");
mon.setCursorPos(1,5)
mon.write("Temperature : "..heat.." deg C");
print("Production : "..power.." EU/t ");
mon.setCursorPos(1,6)
mon.write("Production : "..power.." EU/t");
if(colors.test(rin,colors.blue)) then
print("External cooling is : OFFLINE")
else
print("External cooling is : ONLINE")
end
if(colors.test(rin,colors.purple)) then
print("Internal cooling is : ONLINE")
else
print("Internal cooling is : OFFLINE")
end
if(colors.test(rin,colors.red)) then
print("Power line 1 is : OFF")
else
print("Power line 1 is : ON")
end
if(colors.test(rin,colors.lime)) then
print("Power line 2 is : OFF")
else
print("Power line 2 is : ON")
end
if(colors.test(rin,colors.white)) then
print("Power line 3 is : OFF")
else
print("Power line 3 is : ON")
end
if(colors.test(rin,colors.yellow)) then
print("Power line 4 is : OFF")
else
print("Power line 4 is : ON")
end
if(shutdown or eshutdown) then
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
else
if(heat>4000) then
rout = colors.combine(rout,colors.red)
rs.setBundledOutput("back",rout)
end
if(heat<1500) then
rout = colors.subtract(rout,colors.red)
rs.setBundledOutput("back",rout)
end
end
sensors.setActiveReading(side,sensor,"ReactorContent")
contents = sensors.getReadingAsTable(side,sensor)
– 1*Uranium
– N*Ice
– 1*Coolant
uranium=0
ice=0
coolant=0
for i=1,#contents-1,2 do
if(string.find(contents[i+1],"1*Uran")~=nil) then
uranium=uranium+1;
end
if(string.find(contents[i+1],"1*Cool")~=nil) then
coolant=coolant+1;
end
ice_str = contents[i+1]
if(string.find(ice_str,"Ice")~=nil) then
if(string.sub(ice_str,3,3)=="*") then
num=tonumber(string.sub(ice_str,1,2))
else
num=tonumber(string.sub(ice_str,1,1))
end
ice=ice+num
end
end
print("Uranium cells : "..uranium)
print("Coolant cells : "..coolant)
print("ICE Blocks : "..ice)
mon.setCursorPos(1,8)
mon.write("Uranium cells : "..uranium)
mon.setCursorPos(1,9)
mon.write("Coolant cells : "..coolant)
mon.setCursorPos(1,10)
mon.write("ICE Blocks : "..ice.." ")
cool_detect_old=cool_detect
cool_detect=colors.test(rin,colors.cyan)
if(cool_detect==true and cool_detect_old==false) then
cool_in_transit=cool_in_transit+1
end
print("Coolant cells in transit : "..cool_in_transit)
if(coolant<15 and request_cool_cnt==0) then
request_cool_cnt=200
end
if(request_cool_cnt>0) then
if(request_cool_cnt==200) then
rout = colors.combine(rout,colors.brown)
rs.setBundledOutput("back",rout)
end
if(request_cool_cnt==100) then
rout = colors.subtract(rout,colors.brown)
rs.setBundledOutput("back",rout)
end
if(request_cool_cnt==1) then
cool_in_transit=0
end
request_cool_cnt=request_cool_cnt-1
end
if(colors.test(rin,colors.orange)) then
print("EMERGENCY SHUTDOWN : ENABLED")
shutdown=true
eshutdown=true
else
print("EMERGENCY SHUTDOWN : DISABLED")
eshutdown=false
end
os.startTimer(0.1)
print("")
print("Press S to shutdown reactor and P to power it up.")
end
end
else
print("Can not get readings from reactor core.")
end
Enjoy the code :P/>/>