Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --| _____ Commands _____
- --| 123456789ABCDEFG >> open or close individually
- --| + >> open all
- --| - or 0 >> close all
- --| Space >> show or hide cables value (no graphic calculation)
- --| End >> stop the program
- local Side = "right" -- [top|bottom|left|right|front|back]
- local constInput = "123456789ABCDEFG"
- local isUpdate = true
- function title()
- term.setTextColor(colors.cyan)
- write("Cables state")
- end
- function update(str)
- term.setTextColor(colors.white)
- term.setCursorPos(41, 19)
- write("Update: "..str)
- end
- function termClear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function DB(dec)
- local result = ""
- repeat
- local divres = dec / 2
- local int, frac = math.modf(divres)
- dec = int
- result = math.ceil(frac) .. result
- until dec == 0
- local StrNumber = string.format(result, "s")
- local nbZero = 16 - string.len(StrNumber)
- local sResult = string.rep("0", nbZero)..StrNumber
- return sResult
- end
- function BD(bin)
- return tonumber(bin, 2)
- end
- function Got(input)
- if input == "-" then
- result = 0
- elseif input == "+" then
- result = 65535
- else
- initial = string.reverse(DB(redstone.getBundledOutput(Side)))
- if string.sub(initial, input, input) == "0" then
- charBit = "1"
- else
- charBit = "0"
- end
- if input == "1" then
- final = charBit..string.sub(initial, 2)
- elseif input == "16" then
- final = string.sub(initial, 1, 15)..charBit
- elseif tonumber(input) > 1 and tonumber(input) < 16 then
- final = string.sub(initial, 1, input - 1)..charBit..string.sub(initial, input + 1, 16)
- end
- result = BD(string.reverse(final))
- end
- redstone.setBundledOutput(Side, result)
- end
- function updateGUI()
- termClear()
- title()
- term.setCursorPos(1, 3)
- local expo = 0
- for i = 1, 16 do
- bool = (colors.test (redstone.getBundledOutput(Side), (2^expo)))
- local zero = ""
- if i < 10 then
- zero = "0"
- end
- if bool == true then
- term.setTextColor(colors.lime)
- write(" "..zero..i.." ("..string.sub(constInput, i, i)..") -> ON\n")
- term.setTextColor(colors.white)
- elseif bool == false then
- term.setTextColor(colors.red)
- write(zero..i.." ("..string.sub(constInput, i, i)..") -> OFF\n")
- term.setTextColor(colors.white)
- end
- expo = expo + 1
- end
- update("Yes")
- end
- function pr(Key)
- Got(Key)
- if isUpdate == true then
- updateGUI()
- end
- --* You can add delay between repetitions when a button is maintained down (pressed)
- -- sleep(0.05)
- end
- function main()
- updateGUI()
- while true do
- event, sc = os.pullEvent("key")
- if sc == 11 or sc == 82 or sc == 12 or sc == 74 then
- pr("-")
- elseif sc == 78 or sc == 13 then
- pr("+")
- elseif sc == 57 then
- if isUpdate == true then
- isUpdate = false
- termClear()
- title()
- update("No ")
- else
- isUpdate = true
- updateGUI()
- end
- elseif sc == 2 or sc == 79 then
- pr("1")
- elseif sc == 3 or sc == 80 then
- pr("2")
- elseif sc == 4 or sc == 81 then
- pr("3")
- elseif sc == 5 or sc == 75 then
- pr("4")
- elseif sc == 6 or sc == 76 then
- pr("5")
- elseif sc == 7 or sc == 77 then
- pr("6")
- elseif sc == 8 or sc == 71 then
- pr("7")
- elseif sc == 9 or sc == 72 then
- pr("8")
- elseif sc == 10 or sc == 73 then
- pr("9")
- elseif sc == 30 then
- pr("10")
- elseif sc == 48 then
- pr("11")
- elseif sc == 46 then
- pr("12")
- elseif sc == 32 then
- pr("13")
- elseif sc == 18 then
- pr("14")
- elseif sc == 33 then
- pr("15")
- elseif sc == 34 then
- pr("16")
- elseif sc == 207 then
- termClear()
- return
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement