Arduino PWM代码在一个引脚而不是另一个引脚上工作

时间:2013-09-10 21:56:41

标签: c arduino fade pwm digital-analog-converter

我正在使用Arduino UNO。以下代码适用于PIN 10但不适用于PIN 6.任何人都可以提出原因。我知道每对PWM引脚使用不同的定时器,但我没有对任何定时器做任何事情! 这是代码。

/*
 Fade

 This example shows how to fade an LED on pin 9
 using the analogWrite() function.

 This example code is in the public domain.
 */

int led = 10;           // the pin that the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup()  { 
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
//  Serial.begin(9600);        //for debugging
} 

// the loop routine runs over and over again forever:
void loop()  { 
  // set the brightness of pin 9:
  analogWrite(led, 100);    

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;
//Serial.println(brightness);//for testing purposes
  // reverse the direction of the fading at the ends of the fade: 
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ; 
  }     
  // wait for 30 milliseconds to see the dimming effect    
  delay(30);                            
}

简单地将led = 10行更改为led = 6会导致代码停止工作,即PIN 6上的输出变为零而不是预期的PWM波。

任何建议都将不胜感激。

0 个答案:

没有答案