ESP32C3LuatOSTM1650②动态显示累加整数
- 开源代码
- 2025-08-16 01:03:02

--注意:因使用了sys.wait()所有api需要在协程中使用 -- 用法实例 PROJECT = "ESP32C3_TM1650" VERSION = "1.0.0" _G.sys = require("sys") local tm1650 = require "tm1650" -- 拆分整数,并把最低位数存放在数组最大索引处 local function extractDigits(num) local digits = {20, 20, 20, 20} local index = 4 while num > 0 and index >= 1 do digits[index] = num % 10 num = math.floor(num / 10) index = index - 1 end return digits end --==========数码管显示例子=========== sys.taskInit(function() local cnt=1 local temp local result={} --共阴段码表,0~9的数字 local NUM_TABLE_AX = { [0]=0x3f,[1]=0x06,[2]=0x5b,[3]=0x4f,[4]=0x66, [5]=0x6d,[6]=0x7d,[7]=0x07,[8]=0x7f,[9]=0x6f }; tm1650.init(5,4,tm1650.MODE_LED_OUTPUT) while 1 do result=extractDigits(cnt) -- print(string.format("result的长度=%d",#result)) for i = 1, 4 do if result[i]~=20 then temp=NUM_TABLE_AX[result[i]] --tm1650.print(dig,seg_data) dig的范围是0~3 tm1650.print(i-1,temp) -- print(string.format("result[%d]=%d",i,temp)) end end cnt=cnt+1 sys.wait(100) end end) sys.run()
ESP32C3LuatOSTM1650②动态显示累加整数由讯客互联开源代码栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“ESP32C3LuatOSTM1650②动态显示累加整数”