loading

Sequential Loops for Pin Activation?

Hi, I am starting with Arduino and I am in need of some help. I am trying to sequentially activate 5 pins. I need each pin to be active for 20 seconds in a PWM manner. During their active period I want an arduino sensor to read out the signals emmited by each pin effector. So far I have no problems with the PWM or sensing module code. However I am not able to find how to correctly sequentially activate the pins. I used millis(), etc, but so far I was able to only activate / read the signals from the first pin effector. The sketch doesn´t proceed to the 2nd --- pins. I really very much appreciate your help....Here goes the code so far...

const int greenPin = 11;
const int redPin = 10;
const int irPin = 5;
const int bluePin = 6;
const int yellowPin = 9;
const int outputLDR = 12;

const int ldrSensor = A0;

int brightness = 0;
int increment = 1;

int readingoutputLDR = 0;



void setup()
{
  pinMode(greenPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(irPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  Serial.begin(9600);
 
  setup_parallax();
}

void loop()
{

digitalWrite(outputLDR, HIGH);
readingoutputLDR = analogRead(ldrSensor);

while (millis()<5000)
                {                   
                   if(brightness > 255)
                   {
                    increment = -1; // count down after reaching 255
                   }
                   else if(brightness < 1)
                   {
                   increment = 1; // count up after dropping back down to 0
                   }
                   brightness = brightness + increment;                                    
                   analogWrite(greenPin, brightness); digitalWrite(redPin, LOW); digitalWrite(irPin, LOW); digitalWrite(bluePin, LOW); digitalWrite(yellowPin, LOW);
                   Serial.print("Reading Green"); parallax_output();                   
                 }

delay(1);

while (millis()<5000)
                {                   
                   if(brightness > 255)
                   {
                    increment = -1; // count down after reaching 255
                   }
                   else if(brightness < 1)
                   {
                   increment = 1; // count up after dropping back down to 0
                   }
                   brightness = brightness + increment;
                   delay(1);

                   digitalWrite(greenPin, LOW); analogWrite(redPin, brightness); digitalWrite(irPin, LOW); digitalWrite(bluePin, LOW); digitalWrite(yellowPin, LOW);
                  Serial.print("Reading Red"); parallax_output();                 
                }
 

while (millis()<5000)
                {                   
                   if(brightness > 255)
                   {
                    increment = -1; // count down after reaching 255
                   }
                   else if(brightness < 1)
                   {
                   increment = 1; // count up after dropping back down to 0
                   }
                   brightness = brightness + increment;
                   delay(1);

                   digitalWrite(greenPin, LOW); digitalWrite(redPin, LOW); analogWrite(irPin, brightness); digitalWrite(bluePin, LOW); digitalWrite(yellowPin, LOW);
                    Serial.print("Reading IR"); parallax_output();                 
                }


while (millis()<5000)
                {                   
                   if(brightness > 255)
                   {
                    increment = -1; // count down after reaching 255
                   }
                   else if(brightness < 1)
                   {
                   increment = 1; // count up after dropping back down to 0
                   }
                   brightness = brightness + increment;
                   delay(1);

                   digitalWrite(greenPin, LOW); digitalWrite(redPin, LOW); digitalWrite(irPin, LOW); analogWrite(bluePin, brightness); digitalWrite(yellowPin, LOW);
                   Serial.print("Reading Blue"); parallax_output();                 
                }


while (millis()<5000)
                {                   
                   if(brightness > 255)
                   {
                    increment = -1; // count down after reaching 255
                   }
                   else if(brightness < 1)
                   {
                   increment = 1; // count up after dropping back down to 0
                   }
                   brightness = brightness + increment;
                   delay(1);

                   digitalWrite(greenPin, LOW); digitalWrite(redPin, LOW); digitalWrite(irPin, LOW); digitalWrite(bluePin, LOW); analogWrite(yellowPin, brightness);
                  Serial.print("Reading Yellow"); parallax_output();                 
                }



}


void parallax_output()
{

                   Serial.print("DATA,DATE,TIME,");
                                           
                   Serial.println(readingoutputLDR);
                  
}



void setup_parallax()
{
    Serial.println("CLEARDATA");
    Serial.println("LABEL,Date,Time,Green Response, Red Response, IR Response, Blue Response, Yellow Response");
}

Did you read this ?

milllis

Returns the number of milliseconds since the Arduino board began running
the current program. This number will overflow (go back to zero),
after approximately 50 days.

So your problem is that millis is only <5000 one time since reset.

You need to try

time=millis()+5000

while (time<millis() //etc etc

+1