SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local arg= {...}
|
| 1 | + | dataIsSended= false |
| 2 | - | argData=arg[1] |
| 2 | + | |
| 3 | function binToDec(bin) -- this function is used to convert a binary number into a decimal one | |
| 4 | - | if argData==nil then |
| 4 | + | for i=1,#bin do |
| 5 | - | |
| 5 | + | dec=(string.sub(bin,i,i)*2^i)+dec |
| 6 | - | data="0000000000000000" |
| 6 | + | |
| 7 | return dec | |
| 8 | - | elseif #argData>16 then |
| 8 | + | |
| 9 | - | |
| 9 | + | |
| 10 | - | print("votre donee doit pas contenir plus de 16 bits")
|
| 10 | + | |
| 11 | - | do return end |
| 11 | + | function hexToDec(hex) -- this function is used to convert an hexadecimal number into a decimal one |
| 12 | for i=1,#hex do | |
| 13 | - | else |
| 13 | + | if string.byte(hex,i)>64 then |
| 14 | - | |
| 14 | + | dec=((string.byte(string.sub(hex,i,i),i)-55)*16^i)+dec |
| 15 | - | if #argData<16 then |
| 15 | + | else |
| 16 | dec=(string.sub(hex,i,i)*16^i)+dec | |
| 17 | - | for i=1,16-#argData do |
| 17 | + | |
| 18 | - | |
| 18 | + | |
| 19 | - | argData="0"..argData |
| 19 | + | return dec |
| 20 | - | |
| 20 | + | end |
| 21 | ||
| 22 | function decTobin(dec) -- this function is used to convert a decimal number into a binary one | |
| 23 | local tab={}
| |
| 24 | - | |
| 24 | + | while dec>0 do |
| 25 | - | for i=1,#argData do |
| 25 | + | rest=dec%2 |
| 26 | - | |
| 26 | + | tab[#tab+1]=rest |
| 27 | - | ascii=string.byte(argData,i) |
| 27 | + | dec=(dec-rest)/2 |
| 28 | - | |
| 28 | + | |
| 29 | - | if ascii<48 or ascii>49 then |
| 29 | + | return table.concat(tab) |
| 30 | - | |
| 30 | + | |
| 31 | - | print("la donnee doit etre un nombre binaire")
|
| 31 | + | |
| 32 | - | do return end |
| 32 | + | function decToHex(dec) -- this function is used to convert a decimal number into an hexadecimal one |
| 33 | - | |
| 33 | + | local tab={}
|
| 34 | while dec>0 do | |
| 35 | - | |
| 35 | + | rest=dec%16 |
| 36 | tab[#tab+1]=rest | |
| 37 | dec=(dec-rest)/16 | |
| 38 | - | data=string.reverse(argData) |
| 38 | + | |
| 39 | - | |
| 39 | + | for i=1,#tab do |
| 40 | if tab[i]>9 then | |
| 41 | tab[i]=string.char(tab[i]+55) | |
| 42 | - | argTick=arg[2] |
| 42 | + | |
| 43 | end | |
| 44 | - | if argTick==nil then |
| 44 | + | return table.concat(tab) |
| 45 | - | |
| 45 | + | |
| 46 | - | tick=4 |
| 46 | + | |
| 47 | function sendPMR(data, tick, sideClk, sideDat) -- this function is used to send a serial signal to a programable rednet controler from MFR | |
| 48 | - | else |
| 48 | + | for i=1,#data do |
| 49 | bit=string.sub(data,i,i) | |
| 50 | - | for i=1,#argTick do |
| 50 | + | redstone.setOutput(sideClk,true) |
| 51 | - | |
| 51 | + | |
| 52 | - | ascii=string.byte(argTick,i) |
| 52 | + | redstone.setOutput(sideClk,false) |
| 53 | - | |
| 53 | + | if bit=="1" then |
| 54 | - | if ascii<48 or ascii>57 then |
| 54 | + | redstone.setOutput(sideDat,true) |
| 55 | - | |
| 55 | + | os.sleep(tick*0.05) |
| 56 | - | print("cette donnee doit etre un nombre")
|
| 56 | + | else |
| 57 | - | do return end |
| 57 | + | redstone.setOutput(sideDat,false) |
| 58 | - | |
| 58 | + | os.sleep(tick*0.05) |
| 59 | end | |
| 60 | - | |
| 60 | + | |
| 61 | - | tick=(ascii-48)*10^(i-1) |
| 61 | + | dataIsSended= true |
| 62 | - | |
| 62 | + |