模拟量读取

来源:互联网 发布:杭州淘宝学院 编辑:程序博客网 时间:2024/05/01 05:25
void setup() {  // put your setup code here, to run once:pinMode(13,OUTPUT);Serial.begin(9600);}const int nAnalogPin = A0;int nValue=0;void loop() {  // put your main code here, to run repeatedly:  nValue = analogRead(nAnalogPin);Serial.println(nValue);digitalWrite(13,HIGH);delay(1000);digitalWrite(13,LOW);delay(1000);}
硬件连接:电位器,uno r3,线实验目的:用电位器模拟模拟信号输入,用串口观察电位器旋转时数值变化电位器A,B,C三口,分别连接VCC,A0,GND注意不要将A口接到PIN13口中,这样读到的值为零。