analogWrite()
来源:互联网 发布:程序员 架构师 编辑:程序博客网 时间:2024/06/10 21:09
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 - 13 and 44 - 46. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.
The Arduino Due supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs.
ou do not need to call pinMode() to set the pin as an output before calling analogWrite().
The analogWrite function has nothing to do with the analog pins or the analogRead function.
analogWrite(pin, value)
pin: the pin to write to.
value: the duty cycle: between 0 (always off) and 255 (always on).
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.
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}
- analogWrite()
- Arduino的模拟输出-analogWrite()
- Arduino的详细介绍(基于Mega2560)(分文)——PWM的analogWrite()
- ADO.NET的数据库访问
- Eclipse 设置新建文件后编码默认都为 utf-8 的方法
- UDP,TCP,SCTP区别
- Javscript删除数组中指定元素
- 【内功篇】C语言的输入输出浅析(一)
- analogWrite()
- java中String和StringBuffer区别
- 第四章Python对象
- mybatis配置MySQL的批量查询
- 5、opencv的Mat介绍
- Android 自定义搜索框
- 玩家任务表(每个玩家应该有14条任务记录,需要根据"任务配置表"补全"玩家任务表",原有记录不能修改把每人缺失的任务记录补上)
- 论文阅读Faster RCNN
- 嵌入式学习4(Linux其他常识)