本站改版新增arduino频道
arduino adc 获取电压
#include <Arduino.h> 
#define ain 35 // 定义模拟输入引脚为35
uint16_t adc_value = 0; // 定义一个16位无符号整数变量用于存储ADC采样值
float adc_voltage = 0.0; // 定义一个浮点数变量用于存储ADC电压值
void read_adc() // 定义一个函数用于读取ADC采样值和电压值
{
  adc_value = analogRead(ain); // 从模拟输入引脚读取采样值并存储到adc_value变量中
  adc_voltage = adc_value * (3.3 / 4095); // 根据采样值计算电压值并存储到adc_voltage变量中
  Serial.printf("采样值:%d 电压值:%.2f", adc_value, adc_voltage); // 通过串口打印采样值和电压值
  Serial.println(); // 换行
  delay(500); // 延时500毫秒
}
void setup()
{
  Serial.begin(115200); // 设置串口波特率为115200
}
void loop() 
{
  read_adc(); // 调用read_adc函数读取ADC采样值和电压值
}
Copyright © 2014 ESP56.com All Rights Reserved  
晋ICP备14006235号-22 晋公网安备14108102001165号    
执行时间: 0.0093080997467041 seconds