mirror of
https://github.com/m5stack/ESP-Claw.git
synced 2026-05-20 11:51:49 -07:00
feat(lua_adc): add adc demo lua script
This commit is contained in:
@@ -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")
|
||||
Reference in New Issue
Block a user