Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Monitors TE3 Energy cells and EnderIO capacitor banks and output redstone signals once energy storage drops below set limits.
- -- Will automatically detect direction of adjacent storage device and (optional) Advanced Monitors. If chosen, monitor format should be 1 high and 2 wide.
- -- Redstone signal for the engines will be output out the back of the computer.
- --More details: http://forum.feed-the-beast.com/threads/rhns-1-6-monster-build-journal-and-guide-collection.42664/page-15#post-718973
- local upper = 0.90 --Upper limit for computer to stop transmitting redstone signal. 0.90=90% full.
- local lower = 0.10 --Lower limit for computer to start transmitting redstone signal.
- --Device detection
- isError=0
- function detectDevice(DeviceName)
- DeviceSide="none"
- for k,v in pairs(redstone.getSides()) do
- if peripheral.getType(v)==DeviceName then
- DeviceSide = v
- break
- end
- end
- return(DeviceSide)
- end
- MonitorSide=detectDevice("monitor")
- if MonitorSide~="none" then
- monitor=peripheral.wrap(MonitorSide)
- print ("Monitor on the " .. MonitorSide .. " connected.")
- else
- print ("Warning - No Monitor attached, continuing without.")
- end
- CellSide=detectDevice("cofh_thermalexpansion_energycell")
- if CellSide~="none" then
- cell=peripheral.wrap(CellSide)
- print ("TE Energy cell on the " .. CellSide .. " connected.")
- else
- CellSide=detectDevice("tile_enderio_blockcapacitorbank_name")
- if CellSide~="none" then
- cell=peripheral.wrap(CellSide)
- print ("EnderIO capacitorbank on the " .. CellSide .. " connected.")
- else
- print ("*ERROR* - No Energy storage attached, halting code!")
- return
- end
- end
- --Main code
- redstone.setOutput("back", false) --Defaulting to off
- --If monitor is attached, write data on monitor
- if MonitorSide~="none" then
- monitor.clear()
- monitor.setBackgroundColour((colours.grey))
- monitor.setCursorPos(1,4)
- monitor.write(" ON ")
- monitor.setBackgroundColour((colours.green))
- monitor.setCursorPos(5,4)
- monitor.write(" OFF ")
- monitor.setBackgroundColour((colours.black))
- end
- --Main loop
- while true do
- --Get storage values
- eNow = cell.getEnergyStored("left")
- eMax = cell.getMaxEnergyStored("left")
- --Compute ratio
- fill = (eNow / eMax)
- --If monitor is attached, write data on monitor
- if MonitorSide~="none" then
- monitor.setCursorPos(11,2)
- monitor.write("Storage:")
- monitor.setCursorPos(11,3)
- monitor.write(eNow)
- monitor.setCursorPos(11,4)
- monitor.write("Of:")
- monitor.setCursorPos(11,5)
- monitor.write(eMax)
- monitor.setCursorPos(1,2)
- monitor.write("Engines:")
- end
- if fill > upper then
- --energylevel is over upper level, turning redstone signal off
- redstone.setOutput("back", false)
- if MonitorSide~="none" then
- monitor.setBackgroundColour((colours.grey))
- monitor.setCursorPos(1,4)
- monitor.write(" ON ")
- monitor.setBackgroundColour((colours.green))
- monitor.setCursorPos(5,4)
- monitor.write(" OFF ")
- monitor.setBackgroundColour((colours.black))
- end
- elseif fill < lower then
- --energy level is below lower limit, turning redstone signal on
- redstone.setOutput("back", true)
- if MonitorSide~="none" then
- monitor.setBackgroundColour((colours.green))
- monitor.setCursorPos(1,4)
- monitor.write(" ON ")
- monitor.setBackgroundColour((colours.grey))
- monitor.setCursorPos(5,4)
- monitor.write(" OFF ")
- monitor.setBackgroundColour((colours.black))
- end
- end
- sleep(1)
- end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement