SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local component = require("component") |
| 1 | + | local component = require("component") -- This whole block is to get the addresses of the "hardware" used and imports the libraries component, sides and term.
|
| 2 | - | local sides = require("sides") |
| 2 | + | local sides = require("sides")
|
| 3 | - | local term = require("term") |
| 3 | + | local term = require("term")
|
| 4 | - | local redstoneAddress = component.get("ace") |
| 4 | + | local redstone = component.proxy(component.redstone.address) |
| 5 | - | local energyAddress = component.get("d78") |
| 5 | + | local energyCell = component.proxy(component.energy_device.address) |
| 6 | - | local redstone = component.proxy(redstoneAddress) |
| 6 | + | |
| 7 | - | local energyCell = component.proxy(energyAddress) |
| 7 | + | local redstoneSide = 0 |
| 8 | - | local energyPercent = (energyCell.getEnergyStored())/(energyCell.getMaxEnergyStored())*100 |
| 8 | + | local energySide = 0 |
| 9 | - | local x = 0 |
| 9 | + | local highEnergy = 0 |
| 10 | - | local y = 2 --Used for the power rate calculations |
| 10 | + | local lowEnergy = 0 |
| 11 | - | |
| 11 | + | local x = 0 -- Used for the if statements in the while statement in the main block. |
| 12 | - | local function powerRate() |
| 12 | + | 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. |
| 13 | - | local a = energyCell.getEnergyStored() |
| 13 | + | |
| 14 | - | local b = energyCell.getEnergyStored() |
| 14 | + | local function savedSettings() |
| 15 | - | local c = (b-a)/20*y |
| 15 | + | |
| 16 | - | return(c) |
| 16 | + | |
| 17 | ||
| 18 | - | |
| 18 | + | local function settings() |
| 19 | - | term.clear() |
| 19 | + | |
| 20 | - | io.write("Power Controller v.1.0\n") |
| 20 | + | io.write("On which side should the redstone be output?\n")
|
| 21 | - | os.sleep(1) |
| 21 | + | redstoneSide = io.read() |
| 22 | - | term.clear() |
| 22 | + | io.write("On which side is the energy cell?\n")
|
| 23 | - | |
| 23 | + | energySide = io.read() |
| 24 | - | while true do |
| 24 | + | io.write("What is the desired high energy percentage threshold?\n")
|
| 25 | - | if energyPercent > 75 and not (x == 1) then |
| 25 | + | highEnergy = tonumber(io.read()) |
| 26 | - | x = 1 |
| 26 | + | io.write("What is the desired low energy percentage threshold?\n")
|
| 27 | - | redstone.setOutput(sides.right,0) |
| 27 | + | lowEnergy = tonumber(io.read()) |
| 28 | - | redstone.setOutput(sides.up,0) |
| 28 | + | |
| 29 | - | term.clear() |
| 29 | + | end |
| 30 | - | term.setCursor(1,1) |
| 30 | + | |
| 31 | - | io.write("Too much power! shutting off generation.\n") |
| 31 | + | local function energyPercent() |
| 32 | - | elseif (25 < energyPercent) and (energyPercent <= 75) and not (x == 2) then |
| 32 | + | local energy = (energyCell.getEnergyStored())/(energyCell.getMaxEnergyStored())*100 |
| 33 | - | x = 2 |
| 33 | + | return energy |
| 34 | - | redstone.setOutput(sides.right,15) |
| 34 | + | end |
| 35 | - | redstone.setOutput(sides.up,0) |
| 35 | + | |
| 36 | - | term.clear() |
| 36 | + | local function powerRate() -- In essence, this takes an approximate derivative of the energy stored in function of time. |
| 37 | - | term.setCursor(1,1) |
| 37 | + | local a = energyCell.getEnergyStored() |
| 38 | - | io.write("Power is stabalized") |
| 38 | + | os.sleep(y) |
| 39 | - | elseif energyPercent <= 25 and not (x == 3) then |
| 39 | + | local b = energyCell.getEnergyStored() |
| 40 | - | x = 3 |
| 40 | + | local c = (b-a)/20*y |
| 41 | - | redstone.setOutput(sides.right,15) |
| 41 | + | term.setCursor(1,2) |
| 42 | - | redstone.setOutput(sides.up,15) |
| 42 | + | term.clearLine() |
| 43 | - | term.clear() |
| 43 | + | io.write("RF per tick : "..c.."\n")
|
| 44 | - | term.setCursor(1,1) |
| 44 | + | end |
| 45 | - | io.write("Power is being built up!\n") |
| 45 | + | |
| 46 | - | end |
| 46 | + | local function highEnergy() |
| 47 | - | os.sleep(y) |
| 47 | + | x = 1 |
| 48 | - | term.setCursor(1,2) |
| 48 | + | redstone.setOutput(sides[redstoneSide],0) |
| 49 | - | term.clearLine() |
| 49 | + | term.clear() |
| 50 | - | io.write("RF per tick :"..powerRate()) |
| 50 | + | term.setCursor(1,1) |
| 51 | io.write("Too much power! shutting off generation.\n")
| |
| 52 | end | |
| 53 | ||
| 54 | local function lowEnergy() | |
| 55 | x = 2 | |
| 56 | redstone.setOutput(sides[redstoneSide],15) | |
| 57 | term.clear() | |
| 58 | term.setCursor(1,1) | |
| 59 | io.write("Power is being built up!\n")
| |
| 60 | end | |
| 61 | ||
| 62 | ||
| 63 | term.clear() | |
| 64 | io.write("Power Controller v.1.0\n")
| |
| 65 | os.sleep(1) | |
| 66 | term.clear() | |
| 67 | askSides() | |
| 68 | ||
| 69 | while true do | |
| 70 | if energyPercent() > highEnergy and not (x == 1) then | |
| 71 | highEnergy() | |
| 72 | elseif energyPercent() <= lowEnergy and not (x == 2) then | |
| 73 | lowEnergy() | |
| 74 | end | |
| 75 | powerRate() | |
| 76 | end |