Guest User

serialRednet

a guest
Dec 20th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. local arg= {...}
  2. arg1=arg[1]
  3.  
  4. if arg1==nil then
  5.  
  6.   data="0000000000000000"
  7.  
  8. elseif #arg1>16 then
  9.  
  10.   print("votre donee doit pas contenir plus de 16 bits")
  11.  
  12. elseif #arg1<16 then
  13.  
  14.   for i=1,16-#arg1 do
  15.    
  16.     arg1="0"..arg1
  17.    
  18.   end
  19.  
  20. else
  21.    
  22.   for i=1,#arg1 do
  23.  
  24.   ascii=string.byte(arg1,i)
  25.  
  26.     if ascii<48 or ascii>49 then
  27.    
  28.       print("la donnee doit etre un nombre binaire")
  29.       do return end
  30.      
  31.     end
  32.  
  33.   end
  34.  
  35.   data=string.reverse(arg1)
  36.  
  37. end
  38.  
  39. arg2=arg[2]
  40.  
  41. if arg2==nil then
  42.  
  43.   tick=4
  44.  
  45. else
  46.  
  47.   for i=1,#arg2 do
  48.    
  49.     ascii=string.byte(arg2,i)
  50.    
  51.     if ascii<48 or ascii>57 then
  52.      
  53.       print("cette donnee doit etre un nombre")
  54.       do return end
  55.              
  56.     end
  57.      
  58.     tick=(ascii-48)*10^(i-1)
  59.      
  60.   end      
  61.    
  62. end
  63.  
  64. arg3=arg[3]
  65. arg4=arg[4]
  66.  
  67. if arg3==nil or arg4==nil then
  68.  
  69.   sideclk="right"
  70.   sidedat="back"
  71.  
  72. elseif (arg4~="right" and arg4~="left" and arg4~="top" and arg4~="bottom" and arg4~="front" and arg4~="back") or (arg3~="right" and arg3~="left" and arg3~="top" and arg3~="bottom" and arg3~="front" and arg3~="back") then
  73.  
  74.   print("cote invalide les cote valides sont: front,back,top,bottom,right,left")
  75.   do return end
  76.  
  77. elseif arg4==arg3 then
  78.  
  79.   print("vous ne pouvez pas envoyer la donnee et l'horloge sur le meme cable redstone")
  80.   do return end
  81.  
  82. elseif peripheral.getType(arg4)~="factoryredstonecable" or peripheral.getType(arg3)~="factoryredstonecable" then
  83.  
  84.   print("votre cable doit etre un rednet cable venant du mod Mine Factory Reloaded ces cable doivent etre connecte a un programable rednet controler qui effectuera la desserialisation")
  85.   do return end
  86.  
  87. else
  88.  
  89.   sideclk=arg3
  90.   sidedat=arg4
  91.  
  92. end
  93.  
  94. for i=1,#data do
  95.  
  96.   bit=string.sub(data,i,i)
  97.   redstone.setOutput(sideclk,true)
  98.   os.sleep(tick*0.05)
  99.   redstone.setOutput(sideclk,false)
  100.  
  101.   if bit=="1" then
  102.    
  103.     redstone.setOutput(sidedat,true)
  104.     os.sleep(tick*0.05)
  105.  
  106.   else
  107.    
  108.     redstone.setOutput(sidedat,false)
  109.     os.sleep(tick*0.05)
  110.  
  111.   end
  112.  
  113. end
Advertisement
Add Comment
Please, Sign In to add comment