feat(lua_adc): add adc demo lua script

This commit is contained in:
Xiangao Lu
2026-04-22 21:51:29 +08:00
parent a5cc23de9d
commit 53351e74ca
@@ -0,0 +1,30 @@
local adc = require("adc")
local delay = require("delay")
local ADC_GPIO = 4
local SAMPLE_COUNT = 5
local SAMPLE_INTERVAL_MS = 200
local ch = adc.new(ADC_GPIO)
print(string.format(
"[adc_demo] reading gpio=%d for %d samples...",
ch:gpio(),
SAMPLE_COUNT
))
for i = 1, SAMPLE_COUNT do
print(string.format(
"[adc_demo] sample %d/%d: %d mV",
i,
SAMPLE_COUNT,
ch:read()
))
if i < SAMPLE_COUNT then
delay.delay_ms(SAMPLE_INTERVAL_MS)
end
end
ch:close()
print("[adc_demo] done")