Posted 31 March 2012 - 06:52 PM
This is my first worth while script i made to automatically charge my EU storages from a reactor. It also detects when replacement uranium is needed and displays the current state of the reactor on a monitor.
This script requires both RP2 and IC2.
[attachment=135:ReactorWiringDiagram.png]Hopefully there is enough information the the code and diagram to get you started with it easily.
edit: Thanks sabian
This script requires both RP2 and IC2.
Spoiler
-- The Bobostno Reactor Controller
-- by Bobostno
--
-- This scrip uses both IC2 and RP2 mods
-- Wiring setup is as follows:
-- Reactor Power: White
-- EU Detector: Yellow
-- First storage from reactor(eg. MFE): Red (set to imit redstone on full)
-- Last storage from reactor: Orange (set to imit redstone on empty)
-- Default: Monitor on back and bundled wire on top
--
-- Have Fun!
-- Initial Setup
local monitor = peripheral.wrap("back") -- Chnage "back" to side of your monitor
local nSide = "top" -- change to side of your bundled cable
local reactorOffNum = colours.white
local reactorOn = false
local stateChange = 0
local state = 10
rs.setBundledOutput( nSide, reactorOffNum)
term.clear()
term.setCursorPos(1,1)
print("Welcome to The Bobostno Reactor Controller!")
-- Refresh the monitor
function refresh(omg)
term.redirect( monitor )
term.clear()
term.setCursorPos(1,1)
term.write("Reactor: ")
if omg then -- omg true in error state
print("ERROR")
return
end
if reactorOn then print("On")
else print("Off")
end
term.write("Proccess: ")
if state == 1 then print("Turning Off")
elseif state == 3 then print("Turning On")
else print("Doing Nothing")
end
term.write("Out of uranium: ")
if state == 6 or state == 7 then print("Yes")
else print("No")
end
term.restore()
end
-- Get inputs and place in array
function checkStatus()
local full = rs.testBundledInput( nSide, colours.red)
local empty = rs.testBundledInput( nSide, colours.orange)
local current = rs.testBundledInput( nSide, colours.yellow)
if reactorOn then areactor = true
else areactor = false
end
return{full, empty, current, areactor}
end
-- Choose defined states from all inputs and outputs
function detectState(stateIn)
if stateIn[1] and stateIn[4] then
state = 1
elseif stateIn[1] and not stateIn[4] or not stateIn[1] and not stateIn[2] and not stateIn[4] then
state = 2
elseif stateIn[2] and not stateIn[4] then
state = 3
elseif stateIn[2] and stateIn[4] and stateIn[3] then
state = 4
elseif not stateIn[1] and not stateIn[2] and stateIn[3] and stateIn[4] then
state = 5
elseif not stateIn[1] and not stateIn[2] and not stateIn[3] and stateIn[4] then
state = 6
elseif not stateIn[1] and stateIn[2] and not stateIn[3] and stateIn[4] then
state = 7
else
state = 8
end
end
-- Change Outputs based on current state and report on computer
function setOutput()
if state == 1 then
rs.setBundledOutput( nSide, reactorOffNum)
reactorOn = false
print("Turning reactor off.")
elseif state == 3 then
rs.setBundledOutput( nSide, 0)
reactorOn = true
print("Turning reactor on")
end
end
-- Display current display on computer
function printState()
print("Current state: ", state)
stateChange = state
end
-- Main loop
while true do
local currentStatus = checkStatus()
detectState(currentStatus)
setOutput()
if state == 8 then -- If Error state tell user of error
refresh(true)
print("ERROR! Closing")
rs.setBundledOutput( nSide, reactorOffNum)
print("<Full: ", currentStatus[1], "> <Empty: ", currentStatus[2], ">")
print("<Current: ", currentStatus[3], "> <Reactor: ", currentStatus[4], ">")
return
end
if stateChange ~= state then
refresh(false)
printState()
end
sleep(1)
end
[attachment=135:ReactorWiringDiagram.png]
edit: Thanks sabian