Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local net = ...
- -- Protocol: 1-wire
- -- 10 bit frames
- -- 1 tick per bit
- -- hi -> low start
- -- Clock: > .15 for stable
- local hi = 1
- local lo = 0
- local pulse = 0.25
- local state
- print("Waiting for start state")
- state = redstone.getBundledInput(net)
- -- Need to be high before processing
- while state ~= 1 do
- os.pullEvent("redstone")
- state = redstone.getBundledInput(net)
- end
- local ch=0
- local bc=0
- print("Monitor: ", net)
- while true do
- local b = redstone.getBundledInput(net)
- bc = bc + 1
- if state == 1 and b == 1 then
- -- wait until signal change
- --print("wait")
- --os.pullEvent("redstone")
- elseif state == 1 and b == 0 then
- -- Enter receive state
- state = 0
- bc = 1
- ch = 0
- elseif bc == 10 then
- --print("byte: ", ch)
- print(string.char(ch))
- state = 1
- elseif b == 1 then
- ch = bit.bor(ch, bit.blshift(1,bc-2))
- --print(bc, ": ", b, ": ", ch)
- end
- --print(bc, ": ", b)
- os.sleep(pulse) -- 1 MC tick
- if state == 0 then
- -- print(os.time())
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement