Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Minecraft ProjectRed Seven Segment Library For ComputerCraft By : RamiLego4Game
- --
- -- CellMap:
- -- 1
- -- 2 3
- -- 4
- -- 5 6
- -- 7 8
- --
- advanced = {}
- advanced.cellsMap = {}
- advanced.cellsMap[1] = {colors.lightGray,colors.green,colors.cyan,colors.red,colors.brown,colors.purple,colors.blue,colors.black} --Contains the bundled cable bindings of the left cell
- advanced.cellsMap[2] = {colors.white,colors.lime,colors.orange,colors.pink,colors.yellow,colors.magenta,colors.lightBlue,colors.gray} --Contains the bundled cable bindings of the right cell
- --Contains then numbers & characters map
- advanced.numberMap = {}
- advanced.numberMap[0] = {true,true,true,false,true,true,true}
- advanced.numberMap[1] = {false,false,true,false,false,true,false}
- advanced.numberMap[2] = {true,false,true,true,true,false,true}
- advanced.numberMap[3] = {true,false,true,true,false,true,true}
- advanced.numberMap[4] = {false,true,true,true,false,true,false}
- advanced.numberMap[5] = {true,true,false,true,false,true,true}
- advanced.numberMap[6] = {true,true,false,true,true,true,true}
- advanced.numberMap[7] = {true,false,true,false,false,true,false}
- advanced.numberMap[8] = {true,true,true,true,true,true,true}
- advanced.numberMap[9] = {true,true,true,true,false,true,true}
- advanced.numberMap["-"] = {false,false,false,true,false,false,false}
- advanced.numberMap["a"] = {true,true,true,true,true,true,false}
- advanced.numberMap["b"] = {false,true,false,true,true,true,true}
- advanced.numberMap["c"] = {false,false,false,true,true,false,true}
- advanced.numberMap["d"] = {false,false,true,true,true,true,true}
- advanced.numberMap["e"] = {true,true,false,true,true,false,true}
- advanced.numberMap["f"] = {true,true,false,true,true,false,false}
- --Internal function, Ignore.
- function advanced.getColorsTable(cell,num)
- if not num then return {} end
- local colorsT = {}
- for k,v in pairs(advanced.numberMap[num]) do
- if v then table.insert(colorsT,advanced.cellsMap[cell][k]) end
- end
- return colorsT
- end
- --Internal function, Ignore.
- function advanced.combineColorsTable(t)
- return colors.combine(unpack(t))
- end
- --Internal function, Ignore. It sets the characters of the seven segment display, Warning: Doesn't return debug errors !
- function advanced.setCells(num1,num2,side,point)
- local colorsT1 = advanced.getColorsTable(1,num1)
- local colorsT2 = advanced.getColorsTable(2,num2)
- local color1 = advanced.combineColorsTable(colorsT1)
- local color2 = advanced.combineColorsTable(colorsT2)
- local color = advanced.combineColorsTable({color1,color2})
- if point then color = advanced.combineColorsTable({color,advanced.cellsMap[1][8]}) end
- rs.setBundledOutput(side,color)
- end
- --Internal function, Ignore. It sets the display number of the seven segment display, Warning: Doesn't return debug errors !
- function advanced.setNumber(num,side)
- if num >= 99 or num <= -10 then advanced.setCells("-","-",side) return end
- if num >= 0 then
- local n1, n2, point = nil, nil, nil
- if num >= 10 then
- n1 = math.floor(num/10)
- n2 = math.floor(num)-n1*10
- else
- if num-math.floor(num) > 0 then
- n1 = math.floor(num)
- n2 = math.floor((num-math.floor(num))*10)
- else
- n1 = num
- n2 = 0
- end
- point = true
- end
- advanced.setCells(n1,n2,side,point)
- else
- advanced.setCells("-",math.floor(-num),side)
- end
- end
- --Use this function ! It returns debugging errors :D
- --It creates a new seven segment display object
- --Side -> The side that seven segment display is connected to.
- function newSevenSegment(side)
- if type(side) ~= "string" then return error("Side can be only a string, Passed as a "..type(side)) end
- local seg = {}
- seg.side = side
- --It sets the display number of the seven segments display.
- function seg.setNumber(num)
- if type(num) ~= "number" then return error("Number should be only a number, Passed as a "..type(num)) end
- advanced.setNumber(num,seg.side)
- end
- --Advanced !: It sets the cells characters of the seven segments.
- --Point -> to turn on the middle point of the display.
- function seg.setCells(character1,character2,point)
- if type(charater1) ~= "number" and type(charater1) ~= "string" then return error("Character #1 can be only a number or a string, Passed as a "..type(character1)) end
- if type(charater2) ~= "number" and type(charater2) ~= "string" then return error("Character #2 can be only a number or a string, Passed as a "..type(character2)) end
- advanced.setCells(character1,character2,seg.side,point)
- end
- --Clears the seven segments display.
- function seg.clearCells()
- advanced.setCells(nil,nil,seg.side)
- end
- --Plays a demo counting display, It's 112 seconds long !
- function seg.demo()
- local clockTime = -10
- while clockTime < 101 do
- advanced.setNumber(clockTime,seg.side)
- os.sleep(0.1)
- clockTime = clockTime + 0.1
- end
- advanced.setCells("-","-",seg.side)
- os.sleep(1)
- advanced.setCells(nil,nil,seg.side)
- end
- return seg
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement