Fade LED using Pro Mini

Hello Everyone,

I have a perplexing issue. Trying to fade an LED using a Pro Mini....now it works just fine on the Mega board...not on the mini> My code is below and thanks in advance for the help - Scott

const byte pwmLED = A1;

// define directions for LED fade
#define UP 0
#define DOWN 1
 
// constants for min and max PWM
const int minPWM = 0;
const int maxPWM = 255;
 
// State Variable for Fade Direction
byte fadeDirection = UP;
 
// Global Fade Value
// but be bigger than byte and signed, for rollover
int fadeValue = 0;
 
// How smooth to fade?
byte fadeIncrement = 5;
 
// millis() timing Variable, just for fading
unsigned long previousFadeMillis;
 
// How fast to increment?
int fadeInterval = 50;
 
void setup() {
  // put pwmLED into known state (off)
analogWrite(pwmLED, fadeValue); 
}
 
void doTheFade(unsigned long thisMillis) {
if (thisMillis - previousFadeMillis >= fadeInterval) {
if (fadeDirection == UP) {
fadeValue = fadeValue + fadeIncrement;  
if (fadeValue >= maxPWM) {
        // At max, limit and change direction
fadeValue = maxPWM;
fadeDirection = DOWN;
}
} else {
      //if we aren't going up, we're going down
fadeValue = fadeValue - fadeIncrement;
if (fadeValue <= minPWM) {
        // At min, limit and change direction
fadeValue = minPWM;
fadeDirection = UP;
}
}
analogWrite(pwmLED, fadeValue);  
previousFadeMillis = thisMillis;
}
}
 
void loop() {
unsigned long currentMillis = millis();
doTheFade(currentMillis);
}

Now I've also used the below code on a Mega to fade an led and it works:

int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
unsigned long currentTime;
unsigned long loopTime;

void setup()  { 
  // declare any pin to be an output:
pinMode(A1, OUTPUT);
currentTime = millis();
loopTime = currentTime; 
} 

void loop()  { 
currentTime = millis();
if(currentTime >= (loopTime + 35)){  // 20
    // set the brightness of any:
analogWrite(A1, brightness);    

    // change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

    // reverse the direction of the fading at the ends of the fade: 
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ; 
}     
loopTime = currentTime;  // Updates loopTime
}
                           
}

I will add that both sketches will Fade the LED using an UNO and Mega....however when uploaded to a Pro Mini the LED only blinks.

Simple, A1 isn't a PWM pin on a Uno / Nano / Pro Mini...

And if you want to make life simple, have a look at FadeLed :wink:

I've also used several other pins, 13, 12, 11 on the UNO and Mega and the fading works....the pro mini does not...I've just downloaded your FadeLed library and hopefully that will solve the issue

I bed you didn't try 11 on the Pro Mini :wink: From the pins you mention that's the only pin with PWM support on the Pro Mini / Uno / Nano.

Correct... I used pin 11 on the pro mini and the fading worked just fine...on the mega I've used pins 13, 12, 11 and on the uno I've used sketches that make it possible to fade leds without using pwm....the Mini is what thru me off.

Pro Mini is no different then a Uno :wink: Same chip, different size :wink: