圣源电子制作

 找回密码
 立即注册
查看: 5819|回复: 0
打印 上一主题 下一主题

arduino学习笔记14 Arduino的模拟输出

[复制链接]
跳转到指定楼层
楼主
发表于 2012-4-26 16:21:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 SYDZ__顺 于 2012-4-26 16:22 编辑

arduino学习笔记14 Arduino的模拟输出Description 介绍
Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite() on the same pin). The frequency of the PWM signal is approximately 490 Hz.
将模拟值(PWM波)输出到管脚。可用于在不同的光线亮度调节发光二极管亮度或以不同的速度驱动马达。调用analogWrite()后,该引脚将产生一个指定占空比的稳定方波,直到下一次调用analogWrite()(或在同一引脚调用digitalRead()digitalWrite())。 PWM的信号频率约为490赫兹。
On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 through 13. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11. You do not need to call pinMode() to set the pin as an output before calling analogWrite().
在大多数Arduino板(带有ATmega168ATmega328),这个函数工作在引脚35691011。在ArduinoMega,它适用于2-13号引脚。老的带有ATmega8Arduino板只支持91011引脚上使用。你并不需要在调用analogWrite()之前为设置输入引脚而调用pinMode()
The analogWrite function has nothing whatsoever to do with the analog pins or the analogRead function.
这个analogWrite方法与模拟引脚或者analogRead方法毫不相干
Syntax 语法
analogWrite(pin, value)
Parameters 参数
pin: the pin to write to.
pin:输出的引脚号
value: the duty cycle: between 0 (always off) and 255 (always on).
value:占用空:从0(常关)到255(常开)
Returns 返回值
nothing
Notes and Known Issues 备注和已知问题
The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.
引脚56PWM输出将产生高于预期的占空比。这是因为millis()delay()函数,它们共享同一个内部定时器用于产生PWM输出所产生的相互作用。这提醒我们引脚56在多数低占空比的设置(如0- 10)的情况下0数值的结果并没有完全关闭。
Example 例子
Sets the output to the LED proportional to the value read from the potentiometer.
int ledPin = 9;      // LED connected to digital pin 9int analogPin = 3;   // potentiometer connected to analog pin 3int val = 0;         // variable to store the read valuevoid setup(){  pinMode(ledPin, OUTPUT);   // sets the pin as output}void loop(){  val = analogRead(analogPin);   // read the input pin  analogWrite(ledPin, val / 4);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|联系我们|闽公网安备 35012102000020号|闽ICP备11020110号-1|圣源电子

GMT+8, 2024-12-28 05:53 , Processed in 0.039796 second(s), 13 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表