In addition to the specific functions listed below, the analog input pins support 10-bit analog-to-digital conversion (ADC) using the analogRead() function.
貌似arduino已经集成了ADC的功能了.. 我用analogReference(INTERNAL);设置了参考电压1.1v,然后再换算一下,貌似这次两者都一致了,不知道这个温度对不对,哈哈
analogReference(INTERNAL);//set the volt to 1.1v
int i = 0, count = 5, val = 0;
delay(500);
for(i=0;i<count;i++)
{
int v =analogRead(potPin);// 读取传感器的模拟值并赋值给val
Serial.println(v);
val+=v;
delay(100);
}
val = val/count;
//dat=(125*val)>>8;//温度计算公式
dat = val*0.48828125*1.1/5;
delay(100);
Serial.println(dat);//输出显示dat 的值
delay(500);//延时0.5 秒
页:
1
[2]