Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Double Buffer
- --
- -- Originally by etopsirhc
- -- Improved by IndianaX
- --
- -- Don't waste energy of your big power plant
- -- Configure default on start and input/output side
- local allowBufferFlow = false
- local sideI = "right"
- local sideO = "left"
- -- Internal variables
- local gateI = peripheral.wrap(sideI)
- local gateO = peripheral.wrap(sideO)
- local monitor = peripheral.wrap("top")
- local monitorW, monitorH = monitor.getSize()
- local checkI, checkO
- -- The animations on the TOP monitor
- local animation = { {
- " <",
- " <<",
- " <<<",
- " <<< ",
- " <<< ",
- " <<< ",
- "<<< ",
- "<< ",
- "< " }, {
- " --- ",
- " - - ",
- " --- ",
- " -- ",
- " --- ",
- " -- ",
- " --- ",
- " - " } }
- local animationPos = 1
- function writeTerm(text)
- term.clear()
- term.setCursorPos(1, 1)
- term.write(text)
- end
- function writeMon(status)
- -- Clear monitor and set position
- monitor.clear()
- monitor.setCursorPos(1, monitorH/2 +1)
- -- Check existing animation position else go to first
- if animationPos > # animation[status] then animationPos = 1 end
- monitor.write(animation[status][animationPos])
- animationPos = animationPos + 1
- end
- -- Initial Settings
- rs.setOutput(sideI, allowBufferFlow)
- if allowBufferFlow then
- writeTerm("Discharging Front Buffer.")
- else
- writeTerm("Charging Front Buffer.")
- end
- while true do
- -- Get Status
- --checkI = gateI.get()
- checkO = gateO.get()
- -- Check whats todo
- if checkO["No Energy"] and allowBufferFlow == false then
- allowBufferFlow = true
- rs.setOutput(sideI, allowBufferFlow)
- writeTerm("Discharging Front Buffer.")
- elseif checkO["Full Energy"] and allowBufferFlow == true then
- allowBufferFlow = false
- rs.setOutput(sideI, allowBufferFlow)
- writeTerm("Charging Front Buffer.")
- else
- -- Wait to save CPU / do Animation
- sleep(0.9)
- end
- -- Output Status
- if allowBufferFlow then
- writeMon(1)
- else
- writeMon(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment