Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component") -- This whole block is to get the addresses of the "hardware" used and imports the libraries component, sides and term.
- local sides = require("sides")
- local term = require("term")
- local redstone = component.proxy(component.redstone.address)
- local energyCell = component.proxy(component.energy_device.address)
- local redstoneSide = 0
- local energySide = 0
- local highEnergy = 0
- local lowEnergy = 0
- local x = 0 -- Used for the if statements in the while statement in the main block.
- local y = 2 -- Used for the powerRate() calculations to link it to the refresh rate, os.sleep(y).,, in order to get a bigger sample size to calculate the power difference.
- local function savedSettings()
- local function settings()
- io.write("On which side should the redstone be output?\n")
- redstoneSide = io.read()
- io.write("On which side is the energy cell?\n")
- energySide = io.read()
- io.write("What is the desired high energy percentage threshold?\n")
- highEnergy = tonumber(io.read())
- io.write("What is the desired low energy percentage threshold?\n")
- lowEnergy = tonumber(io.read())
- end
- local function energyPercent()
- local energy = (energyCell.getEnergyStored())/(energyCell.getMaxEnergyStored())*100
- return energy
- end
- local function powerRate() -- In essence, this takes an approximate derivative of the energy stored in function of time.
- local a = energyCell.getEnergyStored()
- os.sleep(y)
- local b = energyCell.getEnergyStored()
- local c = (b-a)/20*y
- term.setCursor(1,2)
- term.clearLine()
- io.write("RF per tick : "..c.."\n")
- end
- local function highEnergy()
- x = 1
- redstone.setOutput(sides[redstoneSide],0)
- term.clear()
- term.setCursor(1,1)
- io.write("Too much power! shutting off generation.\n")
- end
- local function lowEnergy()
- x = 2
- redstone.setOutput(sides[redstoneSide],15)
- term.clear()
- term.setCursor(1,1)
- io.write("Power is being built up!\n")
- end
- term.clear()
- io.write("Power Controller v.1.0\n")
- os.sleep(1)
- term.clear()
- askSides()
- while true do
- if energyPercent() > highEnergy and not (x == 1) then
- highEnergy()
- elseif energyPercent() <= lowEnergy and not (x == 2) then
- lowEnergy()
- end
- powerRate()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement