我一直试图让几个菊花链7段显示器显示每个显示不同的信息,但我似乎无法让它工作。无论我尝试打印出来,都会在第一个显示屏上显示。
如何将数据推送到剩下的7段差异? 我做错了什么(除了一切......)
local M = {}
local CS_PIN = 8
local MODS = 4 --number of modules
local DIGS = 8 --number of digits / module
local digits = {}
digits["0"] = 0x7E
digits["1"] = 0x30
digits["2"] = 0x6d
digits["3"] = 0x79
digits["4"] = 0x33
digits["5"] = 0x5b
digits["6"] = 0x5f
digits["7"] = 0x70
digits["8"] = 0x7f
digits["9"] = 0x7b
local function set(reg, data)
gpio.write(CS_PIN, gpio.LOW)
spi.send(1, reg * 256 + data)
gpio.write(CS_PIN, gpio.HIGH)
end
function M.init()
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 16, 8)
gpio.mode(CS_PIN, gpio.OUTPUT)
gpio.write(CS_PIN, gpio.HIGH)
set(0x0B, 7)
set(0x09, 0)
set(0x0F, 0)
set(0x0A, 0)
set(0x0C, 1)
end
function M.write(mod, str)
--this should push the text to the next 7segment module but it doesnt
--instead it prints some jibberish on the second segment
for m = 1, MODS do
if m < mod then
set(0x00, 0)
end
end
local dots = 0
str = string.rep(" ", DIGS - str:gsub("%.", ""):len())..str
for i = 1, str:gsub("%.", ""):len() do
local s = str:gsub("%.", ""):sub(i, i)
local ds = digits[s]
local x = i + dots + 1
if str:sub(x, x) == '.' then
ds = ds + 0x80
dots = dots + 1
end
set(DIGS - i + 1, ds)
end
end
M.init()
M.write(1, '10000000')
M.write(2, '20000000')
M.write(3, '30000000')
M.write(4, '40000000')