This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
blackrabt's profile picture

Ender IO Capacitor Bank monitoring

Started by blackrabt, 26 February 2015 - 01:01 PM
blackrabt #1
Posted 26 February 2015 - 02:01 PM
This is my attempt at a program that monitors an Ender IO capacitor bank. It is adjustable for location of modem, number of capacitors in the bank and the kind of capacitor used. The program will turn on and off a redstone signal when the storage reaches set values, in my case this is used to activate and deactivate a pair of fuel powered generators. The current fill % and the status of the generators is display on a 3Wx1H monitor bank.

I hope you like it and feel free to post suggestions for improvements!

http://pastebin.com/7HBiYXE6


local capacitor_1 = peripheral.wrap("left")
local modem = peripheral.wrap("back")
local monitor = peripheral.wrap("monitor_1")
monitor.setTextColor(1) --text will be white
monitor.setBackgroundColor(128) --background will be gray
monitor.clear() --paint the background
i = 1
--percentage math constants
makePercent = 100
capacitorCount = 5
capacitorBasic = 1000000
capacitorStandard = 5000000
capacitorVibrant = 25000000
totalCapacity = (capacitorCount) * (capacitorStandard)
fillPercentage = 0
difference = 0
while true do
  energyLevel1 = capacitor_1.getEnergyStored()
  energyAdjusted = (energyLevel1) * (capacitorCount)
  --print(energyAdjusted)
  fillLevel = (4500000) * (capacitorCount)
  lowFillLevel = (3000000) * (capacitorCount)
  if energyAdjusted > fillLevel then
	redstone.setOutput("bottom", true)
	monitor.setCursorPos(6, 5)
	monitor.setTextColor(16384) --text will be red
	monitor.write("Generators Inactive")
  end
  if redstone.getOutput("bottom") == true then
	monitor.setCursorPos(6, 5)
	monitor.setTextColor(16384) --text will be red
	monitor.write("Generators Inactive")
  end
  if redstone.getOutput("bottom") == false then
	monitor.setCursorPos(7,5)
	monitor.setTextColor(8192) --text will be green
	monitor.write("Generators Active")
  end
  if energyAdjusted < lowFillLevel then
	redstone.setOutput("bottom", false)
	monitor.setCursorPos(7,5)
	monitor.setTextColor(8192) --text will be green
	monitor.write("Generators Active")
  end
  monitor.setCursorPos(1,1)
  print("Generators with start at "..lowFillLevel.." RF")
  print("Current energy storage is "..energyAdjusted.." RF")
  --monitor.write("Current energy storage is "..energyAdjusted.." RF")
  difference = (totalCapacity) - (energyAdjusted)
  fillAmount = (energyAdjusted) / (totalCapacity)
  fillPercentage = (fillAmount) * (100)
  fillInt = math.floor(fillPercentage)
  monitor.setCursorPos(3,2)
  monitor.setTextColor(1)
  monitor.write("Currently at "..fillInt.."% capacity")
  --monitor.write(string.format("%.2fillPercentage", fillPercentage))
  sleep(2.5)
  monitor.clear()
end
IntelectualMind #2
Posted 29 November 2016 - 11:09 PM
very smooth handling for my setups