Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- local args = {...}
- if args[3] == nil then
- print("usage: " .. shell.getRunningProgram() .. " <comaparator side> <low> <high>")
- error()
- end
- local side = args[1]
- local low = tonumber(args[2])
- local high = tonumber(args[3])
- local on = redstone.getAnalogInput(side) <= low
- function checkSwitch()
- if on then
- if redstone.getAnalogInput(side) >= high then
- on = false
- return true
- end
- else
- if redstone.getAnalogInput(side) <= low then
- on = true
- return true
- end
- end
- return false
- end
- function stateStr(state)
- if state then
- return "on"
- else
- return "off"
- end
- end
- print("startup " .. stateStr(on))
- rednet.broadcast(stateStr(on))
- while true do
- local e, p1, p2 = os.pullEvent()
- print(e)
- if e == "rednet_message" then
- if p2 == "stateplease" then
- rednet.send(p1, stateStr(on))
- print(os.clock() .. " sent " .. stateStr(on) .. " to " .. p1)
- end
- end
- if e == "redstone" then
- print(os.clock() .. " " .. redstone.getAnalogInput(side))
- if checkSwitch() then
- rednet.broadcast(stateStr(on))
- print(os.clock() .. " switch " .. stateStr(on))
- end
- end
- end
Add Comment
Please, Sign In to add comment