Arduino PWM code working on one pin not another

1.1k views Asked by At

I am using Arduino UNO. The following code is working on PIN 10 but not on PIN 6. Can anyone pls suggest a reason. I know that each pair of PWM pins use different Timers but I havent done anything to any timers!! Here's the code.

/*
 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);                            
}

Simply changing the led = 10 line to led = 6 causes the code to stop working, i.e. the output on PIN 6 becomes zero rather than the intended PWM wave.

Any suggestions would be appreciated.

0

There are 0 answers