Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Config
- local redstoneSide = "left" -- redstone output side
- local pollInterval = 1 -- seconds
- local lowThreshold = 0.25
- local highThreshold = 0.75
- -- State
- local redstoneState = false
- -- Function to find a connected energy cube
- function findEnergyCube()
- for _, side in ipairs(peripheral.getNames()) do
- local p = peripheral.wrap(side)
- if p and type(p.getEnergy) == "function" and type(p.getMaxEnergy) == "function" then
- return p, side
- end
- end
- return nil, nil
- end
- -- Discover energy cube
- local ecube, cubeSide = findEnergyCube()
- if not ecube then
- error("No compatible energy cube found.")
- else
- print("Found energy cube on side: " .. cubeSide)
- end
- -- Main loop
- while true do
- local energy = ecube.getEnergy()
- local max = ecube.getMaxEnergy()
- local fill = energy / max
- print(string.format("Energy: %.1f%%", fill * 100))
- if not redstoneState and fill < lowThreshold then
- redstone.setOutput(redstoneSide, true)
- redstoneState = true
- print("Redstone ON")
- elseif redstoneState and fill > highThreshold then
- redstone.setOutput(redstoneSide, false)
- redstoneState = false
- print("Redstone OFF")
- end
- sleep(pollInterval)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement