Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.wrap("left")
- treeoil = peripheral.wrap("back")
- rosin = peripheral.wrap("right")
- modem.open(3)
- os.startTimer(10)
- treeoil_on = true
- rosin_on = false
- steam_percentage = 0
- rs.setOutput("back", treeoil_on)
- rs.setOutput("right", not treeoil_on)
- function toString(bool)
- return bool and "on" or "off"
- end
- function set(treeoil, rosin)
- print(toString(treeoil) .. " " .. toString(rosin))
- treeoil_on = treeoil
- rosin_on = rosin
- rs.setOutput("back", treeoil_on)
- rs.setOutput("right", rosin_on)
- end
- function getPercentage(device)
- return math.floor(100 * (device.getEnergyStored() or 0) / device.getRFCapacity())
- end
- set(true, false)
- while true do
- e, r1, r2, r3, r4 = os.pullEvent()
- if e == "modem_message" or e == "timer" then
- if e == "modem_message" then
- steam_percentage = tonumber(r4)
- elseif e == "timer" then
- os.startTimer(11)
- end
- percentage = getPercentage(rosin)
- if steam_percentage > 90 and (treeoil_on or rosin_on) then
- steam_percentage = tonumber(r4)
- set(false, false)
- elseif (steam_percentage < 10 and not (treeoil_on or rosin_on)) or treeoil_on or rosin_on then
- if percentage > 60 then
- set(false, true)
- else
- set(true, false)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement