向给定引脚写入模拟数值
语法
void analogWrite(uint8 pin, int duty_cycle8)
参数
pin 引脚编号
duty_cycle8 写入的PWM占空比
返回值
无
示例
int analogPin = 3;
int pwmpin = 2;
void setup() {
pinMode(pwmpin, OUTPUT);
pinMode(analogPin, INPUT_ANALOG);
}
void loop() {
int val = analogRead(analogPin);
analogWrite(pwmpin, val * 16);
}