1

我正在使用 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 波。

任何建议,将不胜感激。

4

0 回答 0