Blink without delay, PWM and LED sequences

Hi All,
Sorry if this is an annoying question, but after going over the Blink without delay and a few other examples of that function I'm still confused. What I have is a single LED increasing then decreasing in brightness (greenLED) then I have 6 LED's turning on and off one after another (redLED). What I would like to happen is for the greenLED to be lighting up and down whilst the redLED's go in sequence. But so far my code seems to run and ignore the timers I've put into it. Should be pretty obvious, but I'm completely new to C++ so any help would be greatly appreciated. Here is my code:

int led = 11;
int brightness = 0;
int delayTime = 5;
int ledCount = 7;
int ledPins[] = { 3, 4, 5, 6, 7, 8, 9 };
int ledDelay = 75;


const unsigned long greenLEDinterval = 500;
const unsigned long redLEDinterval = 1000;


unsigned long greenLEDtimer;
unsigned long redLEDtimer;


void setup() {
  pinMode(led, OUTPUT);
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT); 
  greenLEDtimer = millis ();
  redLEDtimer = millis ();

  }
}


void toggleGreenLED ()
{
  while(brightness < 170)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness = brightness +1;
  }
  while(brightness > 5)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness = brightness - 1;
  }
  greenLEDtimer = millis ();  
}
  
void toggleRedLED ()
{
  for (int thisLed = 0; thisLed < ledCount-1; thisLed++) {
    digitalWrite(ledPins[thisLed], HIGH);
    delay(ledDelay);
    digitalWrite(ledPins[thisLed], LOW);
  }
  for (int thisLed = ledCount-1; thisLed > 0; thisLed--) {
    digitalWrite(ledPins[thisLed], HIGH);
    delay(ledDelay);
    digitalWrite(ledPins[thisLed], LOW);
  }
  redLEDtimer = millis (); 
}

void loop ()
  {


  if ( (millis () - greenLEDtimer) >= greenLEDinterval)
     toggleGreenLED ();

  if ( (millis () - redLEDtimer) >= redLEDinterval) 
    toggleRedLED ();
  }

Thanks for any help

Math!

You have a greenLEDinterval of 500...
in the greenLEDtoggle():

while(brightness < 170)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness = brightness +1;
  }

With a delayTime of 5, and the brightnes going from 0 to 169, it will take 850 milliseconds to run this while loop... More than the 500 milliseconds of the greenLEDinterval...
So after running this (and the next) while loop, it returns to the loop(), it has surpassed the 500mS and runs the toggleGreenLED() again...

Your problem is a common one and is caused by the delay() function which stops other code running whilst it does the delay. To compound things you have the delay()s in while loops so are magnifying the problem.

What you need to do is use the value of millis() to determine whether enough time has passed before the next action is required. If so, then do it. If not go round loop() again. You can have several of these timing decisions in loop() so can do more than one thing apparently at the same time.

See Several things at the same time

Ah Silly mistake with the timing! I'll check out that topic as well. Thanks!