Of Millis, Fade and Stay ON or Off

Hello Everyone. I am new here and new to Arduino programming. I am experimenting with millis() to better understand it. I found a sketch at The Bald Engineer to fade an LED up and then down. I think I understand this pretty much. I also read over the Tute here.
I thought I might try altering the code so the led will fade in, then stay on a few seconds, then turn off. However, now I get nothing. Could someone please take a look at the this code and tell me where I am going wrong.

#define UP 0  
#define DOWN 1
 
const int minPWM = 0;
const int maxPWM = 255;
 
byte fadeDirection = UP;
 
int fadeValue = 0;
 
byte fadeIncrement = 5;
 
unsigned long previousFadeMillis;
unsigned long previousMillis;
int fadeInterval = 50;
int onInterval = 3000; 


void setup() {
  analogWrite(pwmLED, fadeValue); 
}
 
void doTheFade(unsigned long thisMillis) {
  
     if (thisMillis - previousFadeMillis >= fadeInterval) {
    
     if (fadeDirection == UP) {
         fadeValue = fadeValue + fadeIncrement;  
     if (fadeValue >= maxPWM) {
 }             
 }       
          fadeValue = maxPWM;
      if (pwmLED, maxPWM)  {
 }      analogWrite(pwmLED, HIGH);
      if (thisMillis - previousMillis >= onInterval) {
 }     analogWrite(pwmLED, LOW);
 }  
  
    previousMillis = thisMillis;
    previousFadeMillis = thisMillis;
  }

 
void loop() {
                                                          // get the current time, for this time around loop
  unsigned long currentMillis = millis();                    // all millis() timer checks will use this time stamp
   
  doTheFade(currentMillis);
}

Use CTRL T ( or CMD T ) to format your code.

What is this ?
if (pwmLED, maxPWM)

You've got braces all over the place in the doTheFade function. Press control-T in the IDE to autoformat it and line up the blocks and you should be able to see where your logic wen't wrong.

if (pwmLED, maxPWM)

What's the comma doing? Did you mean ==?

(Ninja posted by @larryd at least we agree)

Thanks
That was a mistake. I changed it to; if (pwmLED == maxPWM) However, I am still getting nothing on the LED.

Polliwog:
Thanks
That was a mistake. I changed it to; if (pwmLED == maxPWM) However, I am still getting nothing on the LED.

Yeah, you still got braces all over the place. It matters where you put those.

Well guys, still not working. Here is the corrected code. Still does nothing.

// Example Fading LED with analogWrite and millis()
// See baldengineer.com/fading-led-analogwrite-millis-example.html for more information
// Created by James Lewis

#define UP 0
#define DOWN 1

int pwmLED = 5;

const int minPWM = 0;
const int maxPWM = 255;

byte fadeDirection = UP;

int fadeValue = 0;

byte fadeIncrement = 5;

unsigned long previousFadeMillis;
unsigned long previousMillis;
int fadeInterval = 50;
int onInterval = 3000;


void setup() {
  analogWrite(pwmLED, fadeValue);
}

void doTheFade(unsigned long thisMillis) {

  if (thisMillis - previousFadeMillis >= fadeInterval) {

    if (fadeDirection == UP) {
      fadeValue = fadeValue + fadeIncrement;
      if (fadeValue >= maxPWM) { 
         fadeValue = maxPWM;
     }
    }
    if (pwmLED == maxPWM)  {
       analogWrite(pwmLED, HIGH);
    }
    if (thisMillis - previousMillis >= onInterval) {
        analogWrite(pwmLED, LOW);
  
  }
  previousMillis = thisMillis;
  previousFadeMillis = thisMillis;
}
}

Hint

int pwmLED = 5;

. . .

if (pwmLED == maxPWM)

So 5 can't equal 255? Seems like we've already talked about that in this thread.

Thank you. A little help sometimes is all is needed

Well, I did all the corrections suggestions, still see nothing but a dimly lit LED haunting me. Thanks for all your help. It back t the tutorial boards for me.

Show us your latest incarnation.

larryd:
Show us your latest incarnation.

Here it is

 // Example Fading LED with analogWrite and millis()
// See baldengineer.com/fading-led-analogwrite-millis-example.html for more information
// Created by James Lewis

#define UP 0
#define DOWN 1

int pwmLED = 3;

const int minPWM = 0;
const int maxPWM = 255;

byte fadeDirection = UP;

int fadeValue = 0;

byte fadeIncrement = 5;
unsigned long thisMillis2;
unsigned long previousFadeMillis;
unsigned long previousMillis;
int fadeInterval = 50;
int onInterval = 3000;


void setup() {
  analogWrite(pwmLED, fadeValue);
}

void doTheFade(unsigned long thisMillis) {

  if (thisMillis - previousFadeMillis >= fadeInterval) {

    if (fadeDirection == UP) {
      fadeValue = fadeValue + fadeIncrement;
      if (fadeValue >= maxPWM) { 
         fadeValue = maxPWM;
          
       if (fadeValue == maxPWM) {      
         analogWrite(pwmLED, HIGH);
       }  
     }
    } 
    if (pwmLED == HIGH)  {
        
        if (thisMillis - previousMillis >= onInterval) {
      
        analogWrite(pwmLED, LOW);
    
        } 
  previousMillis = thisMillis2;
  previousFadeMillis = thisMillis;
    }
  }
}
void loop() {
  // get the current time, for this time around loop
  unsigned long currentMillis = millis();                    // all millis() timer checks will use this time stamp

  doTheFade(currentMillis);
}

You have:
int pwmLED = 3;

You then you have:
if (pwmLED == HIGH)

You essentially have:
if (pwmLED == HIGH) or with numbers if (3 == HIGH)

Stop, and read the above over and over until you understand the problem :wink: .

    if (fadeValue == maxPWM) {   
         analogWrite(pwmLED, HIGH);

That's not very bright.
(Pun intended)

Hey guys.
My original idea was to fade in a red LED, then hold it high for a for a while. After it has been high for a bit , then fade in a yellow to make orange. Then fade out the red to make yellow only for a time. Then continue with green and blue to simulate a rainbow. To me, it's quite daunting, after learning how to fade without delay.

Thing is, I am getting really frustrated now so I think the best thing is to leave it and go on to some other projects for a while.

Thanks everyone.