Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttonAPI = require("buttonAPI")
- local component = require("component")
- local term = require("term")
- local event = require("event")
- local math = require("math")
- local br = component.br_reactor
- local mon = component.gpu
- local w, h = mon.getResolution()
- local isCooldown = false
- local timerID = nil
- function regulate()
- local bufferCutoff = 500000
- if br.getEnergyStored() > bufferCutoff and br.getActive() == true then
- powerOff()
- isCooldown = false
- elseif br.getEnergyStored() <= bufferCutoff and isCooldown == false then
- isCooldown = true
- powerOn()
- end
- end
- function resetCooldown()
- isCooldown = false
- end
- function fillTable()
- buttonAPI.setTable("Enable", powerOn, 1, 3, (w / 2 - 1.5), (h / 2))
- buttonAPI.setTable("Disable", powerOff, (w / 2 + 1.5), 3, w, (h / 2))
- buttonAPI.setTable("Auto Control", autoControl, 1, (h / 2 + 2), w, (h / 2 + 15))
- buttonAPI.screen()
- end
- function getClick()
- local _,_, x, y = event.pull("touch")
- buttonAPI.checkxy(x, y)
- end
- function powerOn()
- buttonAPI.toggleButton("Enable")
- buttonAPI.toggleButton("Disable")
- br.setActive(true)
- end
- function powerOff()
- buttonAPI.toggleButton("Disable")
- buttonAPI.toggleButton("Enable")
- br.setActive(false)
- end
- function autoControl()
- buttonAPI.toggleButton("Auto Control", 0x00AA00, 0x0000DD)
- if timerID == nil then
- timerID = event.timer(3, regulate, math.huge)
- else
- event.cancel(timerID)
- timerID = nil
- end
- end
- term.clear()
- fillTable()
- buttonAPI.heading("Reactor Control")
- if br.getActive() == true then
- buttonAPI.toggleButton("Enable")
- else
- buttonAPI.toggleButton("Disable")
- end
- while true do
- getClick()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement