Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sides = require("sides")
- function setProxy(address)
- return component.proxy(component.get(address))
- end
- -- inputs
- local lever4 = setProxy("9e801798")
- local lever2 = setProxy("e9bfc284")
- local lever1 = setProxy("364893bf")
- local confirm = setProxy("2ea39d69")
- -- outputs
- local spr1 = setProxy("678a6377")
- local spr2 = setProxy("78fcfad4")
- local spr3 = setProxy("366d2881")
- local spr4 = setProxy("26b09697")
- local spr5 = setProxy("e8c8271f")
- local spr6 = setProxy("b75a65b4")
- local spr7 = setProxy("9a7fa821")
- local loopLock = true
- local res = 0
- local sprinklerTable = {spr1, spr2, spr3, spr4, spr5, spr6, spr7}
- --[[
- local sprinklerTable = {}
- do
- local spradr = {"678a6377", "78fcfad4", "366d2881", "26b09697", "e8c8271f", "b75a65b4", "9a7fa821"}
- for i in 1,8 do
- sprinklerTable[i] = setProxy(spradr[i])
- end
- end
- ]]--
- function checkInputs()
- confirmState = confirm.getInput(sides.north)
- if confirmState > 10 then
- print("confirmed!")
- loopLock = false
- end
- end
- function toggleOutputs(result)
- if result ~= 0 then
- target = sprinklerTable[result]
- if target.getOutput(sides.east) > 10 then
- target.setOutput(sides.east, 0)
- print("Turned sprinkler ", target, " off!")
- elseif target.getOutput(sides.east) == 0 then
- target.setOutput(sides.east, 15)
- print("Turned sprinkler ", target, " on!")
- end
- end
- if result == 0 then
- if confirm.getInput(sides.west) > 10 then
- print("Enabling all sprinklers!")
- toggleAllSprinklers(1)
- elseif confirm.getInput(sides.west) == 0 then
- print("Disabling all sprinklers!")
- toggleAllSprinklers(0)
- end
- end
- end
- -- debug
- function toggleAllSprinklers(selector)
- local state = 0
- if selector == 0 then
- state = 0
- print("State 0")
- else
- state = 15
- print("State 1")
- end
- for i,v in ipairs(sprinklerTable) do
- -- for i, v in pairs(sprinklerTable) do
- v.setOutput(sides.bottom, state)
- print("Set ", v, " to ", state)
- end
- end
- while true do
- --main loop
- while loopLock == true do
- -- check sensor loop
- res = 0
- input1 = lever4.getInput(sides.north)
- input2 = lever2.getInput(sides.north)
- input3 = lever1.getInput(sides.north)
- if input1 > 10 then res = res + 4 end
- if input2 > 10 then res = res + 2 end
- if input3 > 10 then res = res + 1 end
- checkInputs()
- os.sleep(0.5)
- end
- print("Selected sprinkler: ", res)
- toggleOutputs(res)
- os.sleep(4)
- loopLock = true
- term.clear()
- print("Accepting input.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement