Advertisement
Guest User

recv

a guest
Apr 25th, 2014
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. local net = ...
  2.  
  3. -- Protocol: 1-wire
  4. -- 10 bit frames
  5. -- 1 tick per bit
  6. -- hi -> low start
  7. -- Clock: > .15 for stable
  8. local hi = 1
  9. local lo = 0
  10. local pulse = 0.25
  11.  
  12. local state
  13. print("Waiting for start state")
  14. state = redstone.getBundledInput(net)
  15. -- Need to be high before processing
  16. while state ~= 1 do
  17.   os.pullEvent("redstone")
  18.   state = redstone.getBundledInput(net)
  19. end
  20.  
  21. local ch=0
  22. local bc=0
  23. print("Monitor: ", net)
  24. while true do
  25.   local b = redstone.getBundledInput(net)
  26.   bc = bc + 1
  27.  
  28.   if state == 1 and b == 1 then
  29.     -- wait until signal change
  30.     --print("wait")
  31.     --os.pullEvent("redstone")
  32.   elseif state == 1 and b == 0 then
  33.     -- Enter receive state
  34.     state = 0
  35.     bc = 1
  36.     ch = 0
  37.   elseif bc == 10 then
  38.     --print("byte: ", ch)
  39.     print(string.char(ch))
  40.     state = 1
  41.   elseif b == 1 then
  42.     ch = bit.bor(ch, bit.blshift(1,bc-2))
  43.     --print(bc, ": ", b, ": ", ch)
  44.   end
  45.  
  46.   --print(bc, ": ", b)
  47.   os.sleep(pulse) -- 1 MC tick
  48.   if state == 0 then
  49.     -- print(os.time())
  50.   end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement