Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cmp = require("component")
- local colors = require("colors")
- local sides = require("sides")
- local unicode = require("unicode")
- local shell = require("shell")
- local inet = require("internet")
- local rs = cmp.redstone
- local chars = {
- ["1"] = {9, 10},
- ['2'] = {14, 12, 11, 9, 8},
- ['3'] = {14, 11, 10, 9, 8},
- ['4'] = {14, 13, 9, 10},
- ['5'] = {14, 13, 11, 10, 8},
- ['6'] = {14, 13, 11, 10, 8, 12},
- ['7'] = {10, 9, 8},
- ['8'] = {14, 13, 12, 11, 10, 9, 8},
- ['9'] = {14, 13, 11, 10, 9, 8},
- ['0'] = {13, 12, 11, 10, 9, 8}
- }
- local enabled = {
- [1] = {},
- [2] = {}
- }
- local disp1 = sides.east
- local disp2 = sides.west
- local function has_value (tab, val)
- for index, value in ipairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- function tablefind(tab,el)
- for index, value in pairs(tab) do
- if value == el then
- return index
- end
- end
- end
- local function cleanMatrix()
- for i = 0, 15 do
- rs.setBundledOutput(disp1, i, 0)
- end
- for i = 0, 15 do
- rs.setBundledOutput(disp2, i, 0)
- end
- end
- local function toMatrix(num, disp)
- if unicode.len(tostring(num)) > 2 then
- error("Numbers that are longer than 2 digits are not allowed.")
- end
- local side
- if disp == 1 then
- side = disp1
- elseif disp == 2 then
- side = disp2
- end
- numstring = tostring(num)
- for i = 1, tonumber(unicode.len(numstring)) do
- local char = string.sub(numstring, i, i)
- if not chars[char] then
- error("Character "..char.." is unsupported")
- end
- for _, v in pairs(enabled[disp]) do
- if not has_value(chars[char], v) then
- rs.setBundledOutput(side, v, 0)
- table.remove( enabled[disp], tablefind(enabled[disp], v) )
- print("Removed "..tostring(v)..", char "..char)
- end
- end
- for _, v in pairs(chars[char]) do
- if not has_value(enabled[disp], v) then
- if i == 1 then
- rs.setBundledOutput(side, v, 15)
- table.insert(enabled[disp], v)
- print("Added "..tostring(v)..", char "..char)
- elseif i == 2 then
- rs.setBundledOutput(side, v-8, 15)
- table.insert(enabled[disp], v-8)
- print("Added "..tostring(v)..", char "..char)
- end
- end
- end
- end
- end
- ------------------------------------------------------------------------------------
- cleanMatrix()
- for i = 1, 4 do
- toMatrix(i, 1)
- os.sleep(1)
- end
- print(require("serialization").serialize(enabled))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement