Arduino的模拟输入-analogRead()

Description 介绍

Reads the value from the specified analog pin. The Arduino board contains a 6 channel (8 channels on the Mini and Nano, 16 on the Mega), 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. The input range and resolution can be changed using analogReference().

 

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

从指定的模拟引脚读取值。Arduino主板有6个通道(Mini和Nano有8个,Mega有16个),10位AD(模数)转换器。这意味着输入电压0-5伏对应0-1023的整数值。这就是说读取精度为:5伏/1024个单位,约等于每个单位0.049伏(4.9毫伏)。输入范围和进度可以通过analogReference()进行修改。


模拟输入的读取周期为100微秒(0.0001秒),所以最大读取速度为每秒10,000次。

 

Syntax 语法

analogRead(pin)

 

Parameters 参数

pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)

pin:读取的模拟输入引脚号(大多数主板是0-5,Mini和Nano是0-7,Mega是0-15)

 

Returns 返回值

int (0 to 1023)

整数型  int(0到1023)

 

Note 备注

If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).

如果模拟输入引脚没有连接到任何地方analogRead()的返回值也会因为某些因素而波动(如其他模拟输入,你的手与主板靠的太近

 

Example 例子
 
int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
                       // outside leads to ground and +5V
int val = 0;           // variable to store the value read

void setup()
{
  Serial.begin(9600);          //  setup serial
}

void loop()
{
  val = analogRead(analogPin);    // read the input pin
  Serial.println(val);             // debug value
}

  • 7
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值