Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --| _____ Commands _____
  2. --| 123456789ABCDEFG >> open or close individually
  3. --| + >> open all
  4. --| - or 0 >> close all
  5. --| Space >> show or hide cables value (no graphic calculation)
  6. --| End >> stop the program
  7.  
  8. local Side = "right" -- [top|bottom|left|right|front|back]
  9. local constInput = "123456789ABCDEFG"
  10. local isUpdate = true
  11.  
  12. function title()
  13.   term.setTextColor(colors.cyan)
  14.   write("Cables state")
  15. end
  16.  
  17. function update(str)
  18.   term.setTextColor(colors.white)
  19.   term.setCursorPos(41, 19)
  20.   write("Update: "..str)
  21. end
  22.  
  23. function termClear()
  24.   term.clear()
  25.   term.setCursorPos(1,1)
  26. end
  27.  
  28. function DB(dec)
  29.   local result = ""
  30.   repeat  
  31.     local divres = dec / 2
  32.     local int, frac = math.modf(divres)
  33.     dec = int
  34.     result = math.ceil(frac) .. result
  35.   until dec == 0
  36.   local StrNumber = string.format(result, "s")
  37.   local nbZero = 16 - string.len(StrNumber)
  38.   local sResult = string.rep("0", nbZero)..StrNumber
  39.   return sResult  
  40. end
  41.  
  42. function BD(bin)
  43.   return tonumber(bin, 2)
  44. end
  45.  
  46. function Got(input)
  47.   if input == "-" then
  48.     result = 0      
  49.   elseif input == "+" then  
  50.     result = 65535
  51.   else
  52.     initial = string.reverse(DB(redstone.getBundledOutput(Side)))
  53.     if string.sub(initial, input, input) == "0" then
  54.       charBit = "1"
  55.     else
  56.       charBit = "0"
  57.     end  
  58.     if input == "1" then      
  59.       final = charBit..string.sub(initial, 2)  
  60.     elseif input == "16" then
  61.       final = string.sub(initial, 1, 15)..charBit    
  62.     elseif tonumber(input) > 1 and tonumber(input) < 16 then
  63.       final = string.sub(initial, 1, input - 1)..charBit..string.sub(initial, input + 1, 16)
  64.     end
  65.     result = BD(string.reverse(final)) 
  66.   end
  67.   redstone.setBundledOutput(Side, result)
  68. end
  69.  
  70. function updateGUI()
  71.   termClear()
  72.   title()
  73.   term.setCursorPos(1, 3)
  74.   local expo = 0
  75.   for i = 1, 16 do
  76.     bool = (colors.test (redstone.getBundledOutput(Side), (2^expo)))
  77.     local zero = ""
  78.     if i < 10 then
  79.     zero = "0"
  80.     end    
  81.     if bool == true then
  82.     term.setTextColor(colors.lime)
  83.     write("               "..zero..i.." ("..string.sub(constInput, i, i)..") -> ON\n")
  84.     term.setTextColor(colors.white)
  85.     elseif bool == false then
  86.     term.setTextColor(colors.red)
  87.     write(zero..i.." ("..string.sub(constInput, i, i)..") -> OFF\n")
  88.     term.setTextColor(colors.white)
  89.     end
  90.   expo = expo + 1
  91.   end      
  92.   update("Yes")
  93. end
  94.  
  95. function pr(Key)
  96.   Got(Key)
  97.   if isUpdate == true then
  98.     updateGUI()
  99.   end
  100.   --* You can add delay between repetitions when a button is maintained down (pressed)
  101.   -- sleep(0.05)
  102. end
  103.  
  104. function main()
  105.   updateGUI()
  106.   while true do
  107.     event, sc = os.pullEvent("key")  
  108.     if sc == 11 or sc == 82 or sc == 12 or sc == 74 then
  109.        pr("-")
  110.     elseif sc == 78 or sc == 13 then
  111.       pr("+")
  112.     elseif sc == 57 then
  113.       if isUpdate == true then
  114.         isUpdate = false
  115.         termClear()
  116.         title()
  117.         update("No ")
  118.       else
  119.         isUpdate = true
  120.         updateGUI()
  121.       end
  122.     elseif sc == 2 or sc == 79 then
  123.       pr("1")  
  124.     elseif sc == 3 or sc == 80 then
  125.       pr("2")
  126.     elseif sc == 4 or sc == 81 then
  127.       pr("3")
  128.     elseif sc == 5 or sc == 75 then
  129.       pr("4")
  130.     elseif sc == 6 or sc == 76 then
  131.       pr("5")
  132.     elseif sc == 7 or sc == 77 then
  133.       pr("6")
  134.     elseif sc == 8 or sc == 71 then
  135.       pr("7")
  136.     elseif sc == 9 or sc == 72 then
  137.       pr("8")
  138.     elseif sc == 10 or sc == 73 then
  139.       pr("9")
  140.     elseif sc == 30 then
  141.      pr("10")
  142.     elseif sc == 48 then
  143.       pr("11")
  144.     elseif sc == 46 then
  145.       pr("12")
  146.     elseif sc == 32 then
  147.       pr("13")
  148.     elseif sc == 18 then
  149.       pr("14")
  150.     elseif sc == 33 then
  151.       pr("15")
  152.     elseif sc == 34 then
  153.       pr("16")
  154.     elseif sc == 207 then
  155.       termClear()  
  156.       return
  157.     end
  158.   end
  159. end
  160.  
  161. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement