local function ADC0_Task() local adcValue, voltValue = 0, 0 local result = adc.open(0)--打开ADC通道0 whiletruedo log.info("ADC0_Task", "ADC0_Task_run") adcValue, voltValue = adc.read(0)--读取通道0的值 --adc.read接口返回的voltval放大了3倍,所以需要除以3还原成原始电压 if adcValue ~= 0xffff then log.info("ADC 0的原始测量数据和电压值:", adcValue, voltValue) end sys.wait(1000) end adc.close(0) end
ADC1的测试程序如下
1 2 3 4 5 6 7 8 9 10 11 12 13
local function ADC1_Task() local adcValue, voltValue = 0, 0 local result = adc.open(1) whiletruedo log.info("ADC1_Task", "ADC1_Task_run") adcValue, voltValue = adc.read(1) if adcValue ~= 0xffff then log.info("ADC 1的原始测量数据和电压值:", adcValue, voltValue) end sys.wait(1000) end adc.close(1) end
local function ADC0_Task() local adcValue, voltValue = 0, 0 local result = adc.open(0)--打开ADC通道0 whiletruedo log.info("ADC0_Task", "ADC0_Task_run") adcValue, voltValue = adc.read(0)--读取通道0的值 --adc.read接口返回的voltval放大了3倍,所以需要除以3还原成原始电压 if adcValue ~= 0xffff then log.info("ADC 0的原始测量数据和电压值:", adcValue, voltValue) end sys.wait(1000) end adc.close(0) end local function ADC1_Task() --初始化GPIO 比如GPIO_38 local adcValue, voltValue = 0, 0 local result = adc.open(1) whiletruedo log.info("ADC1_Task", "ADC1_Task_run") adcValue, voltValue = adc.read(1) if adcValue ~= 0xffff then log.info("ADC 1的原始测量数据和电压值:", adcValue, voltValue) end sys.wait(1000) end adc.close(1) end
local function user_main() sys.taskInit(ADC0_Task) sys.taskInit(ADC1_Task) end