Multiple LED At Once

We have started a new project, and are admittedly quite stuck.

We already have a working product, but now we want to put it on a PCB. Due to size constraints, we are limited to a 3.7V Lipo Battery, and our circuit board can only be 40mm in diameter, and 30mm high. It is simply a circle of LEDs.

For right now, we are trying to make it so that on start up, 6 LEDS randomly flicker for 10 seconds. Then, they will shut off and have 11 LEDs grow bright, BUT one of the LEDs (the center one) should grow bright 1.5 seconds before the other 10....

I haven't gotten to the center LED quite yet..I'm trying to figure out the flicker first.

This is the code that I have so far:

int startup_led1 = 2;
int startup_led2 = 3;
int startup_led3 = 4;
int startup_led4 = 5;
int startup_led5 = 6;
int startup_led6 = 7;

int special_led1 = 10;

int brightness   = 50;

int fade         = 50;

unsigned long starttime;
unsigned long endtime;

long randON = 0;
long randOFF = 0;
int  randLED = 0;
void setup(){
  pinMode(startup_led1, OUTPUT);
  pinMode(startup_led2, OUTPUT);
  pinMode(startup_led3, OUTPUT);
  pinMode(startup_led4, OUTPUT);
  pinMode(startup_led5, OUTPUT);
  pinMode(startup_led6, OUTPUT);
  pinMode(special_led1, OUTPUT); 
  
  randomSeed (analogRead (0)); 
}

void loop(){
  
 starttime = millis();
 endtime   = starttime;
 
 while((endtime - starttime) <= 10000){
 randON = random(100,200); //tweak these for faster blink
 randOFF = random(200,900); //tweak these for faster blink
 randLED = random(1,6);
 
 if(randLED == 1){
 digitalWrite(startup_led1, HIGH);
 delay(randON);
 digitalWrite(startup_led1, LOW);
 delay(randOFF);
 }
 
 if(randLED == 2){
 digitalWrite(startup_led2, HIGH);
 delay(randON);
 digitalWrite(startup_led2, LOW);
 delay(randOFF);
 }
 
 if(randLED == 3){
 digitalWrite(startup_led3, HIGH);
 delay(randON);
 digitalWrite(startup_led3, LOW);
 delay(randOFF);
 }
 
 if(randLED == 4){
 digitalWrite(startup_led4, HIGH);
 delay(randON);
 digitalWrite(startup_led4, LOW);
 delay(randOFF);
 }
 
 if(randLED == 5){
 digitalWrite(startup_led5, HIGH);
 delay(randON);
 digitalWrite(startup_led5, LOW);
 delay(randOFF);
 }
 
 if(randLED == 6){
 digitalWrite(startup_led6, HIGH);
 delay(randON);
 digitalWrite(startup_led6, LOW);
 delay(randOFF);
 endtime = millis();
 }
 }
 
 while(brightness <= 1000){
 brightness = brightness + fade;
 
 digitalWrite(special_led1, brightness);
 delay(30);
 
 }
 
 }

Any help would be GREATLY appreciated.

Hello TheOrcadian

Can you say what help you need? What problems are you getting when you run this code? What is it doing, versus what you want it to do?

One thing to do is auto-format the code in the Arduino IDE (with CTRL-T). This will line up the indent levels correctly and show the structure of the program more clearly.

Something to check straight away is your 10 second timing while loop:

 while((endtime - starttime) <= 10000)

Until either endtime or startime is updated, the comparison will always have the same answer. So you might want to check in what circumstances you update either of them

Lastly, you probably realise that when you get to each delay() instruction to flicker a particular LED, the program stops at that instruction until the delay is over. So you can only flicker one LED at a time with the way the program is designed.

This may meet your requirements. But if you need more things to happen at the same time, you should look at the "blink without delay" example program and use the technique it shows.

All the best

Ray

Hackscribble:
Something to check straight away is your 10 second timing while loop:

 while((endtime - starttime) <= 10000)

Until either endtime or startime is updated, the comparison will always have the same answer. So you might want to check in what circumstances you update either of them

Or just change it to: while((millis()- starttime) <= 10000)

We already have a working product

We have started a new project, and are admittedly quite stuck.

Not to be nit picky , but when you read the above statements , don't they seem to contradict each other ?
Either the product is working or it is not . (admittedly the issues you are have sound trivial but nevertheless they are issues)
How can you in the same sentence say the product is working and that your are stuck ?
Which is it ?

I added some extra leds and made some changes:

int startup_led1 = 2;
int startup_led2 = 3;
int startup_led3 = 4;
int startup_led4 = 5;
int startup_led5 = 6;
int startup_led6 = 7;
int special_led7 = 8;
int special_led8 = 9;
int special_led1 = 10;


int brightness   = 5;

int fade         = 5;

unsigned long starttime;
unsigned long endtime;

long randON = 0;
long randOFF = 0;
int  randLED = 0;

void setup()
{
  pinMode(startup_led1, OUTPUT);
  pinMode(startup_led2, OUTPUT);
  pinMode(startup_led3, OUTPUT);
  pinMode(startup_led4, OUTPUT);
  pinMode(startup_led5, OUTPUT);
  pinMode(startup_led6, OUTPUT);
  pinMode(special_led7, OUTPUT); 
  pinMode(special_led8, OUTPUT); 
   pinMode(special_led1, OUTPUT); 
  
  randomSeed (analogRead (0)); 
  
 
}

void loop()
{
   digitalWrite(startup_led1, HIGH);   // turns the LED on
   digitalWrite(startup_led1, LOW);    // turns the LED off
   digitalWrite(startup_led2, HIGH);   // turns the LED on
   delay(30);                // waits for a second
   digitalWrite(startup_led2, LOW);    // turns the LED off
   delay(30);    
   digitalWrite(startup_led3, HIGH);   // turns the LED on
   delay(30);               // waits for a second
   digitalWrite(startup_led3, LOW);    // turns the LED off
   delay(30);    
   digitalWrite(startup_led4, HIGH);   // turns the LED on
   delay(30);               // waits for a second
   digitalWrite(startup_led4, LOW);    // turns the LED off
   delay(30);    
   digitalWrite(startup_led5, HIGH);   // turns the LED on
   delay(30);               // waits for a second
   digitalWrite(startup_led5, LOW);    // turns the LED off
   delay(30);    
   digitalWrite(startup_led6, HIGH);   // turns the LED on
   delay(30);               // waits for a second
   digitalWrite(startup_led6, LOW);    // turns the LED off
   delay(30);    
   digitalWrite(special_led7, HIGH);   // turns the LED on
   delay(30);               // waits for a second
   digitalWrite(special_led7, LOW);    // turns the LED off
   delay(30);    
   digitalWrite(special_led8, HIGH);   // turns the LED on
   delay(30);               // waits for a second
   digitalWrite(special_led8, LOW);    // turns the LED off
   delay(30);    
   digitalWrite(special_led1, HIGH);   // turns the LED on
   delay(30);               // waits for a second
   digitalWrite(special_led1, LOW);    // turns the LED off
   delay(30);    
  
 /////////////////////////////////////////////////////////////////
 
  
  for (int i=0;i<4;i++)
  {
   digitalWrite(startup_led1, HIGH);   // turns the LED on
   digitalWrite(startup_led2, HIGH);   // turns the LED on
   digitalWrite(startup_led3, HIGH);   // turns the LED on
   digitalWrite(startup_led4, HIGH);   // turns the LED on
   digitalWrite(startup_led5, HIGH);   // turns the LED on
   digitalWrite(startup_led6, HIGH);   // turns the LED on
   digitalWrite(special_led7, HIGH);   // turns the LED on
   digitalWrite(special_led8, HIGH);   // turns the LED on
   digitalWrite(special_led1, HIGH);   // turns the LED on

  ////////////////////////////////////////////////////////////////
  delay(80);    
  ////////////////////////////////////////////////////////////////
  digitalWrite(startup_led1, LOW);    // turns the LED off
  digitalWrite(startup_led2, LOW);    // turns the LED off
  digitalWrite(startup_led3, LOW);    // turns the LED off
  digitalWrite(startup_led4, LOW);    // turns the LED off
  digitalWrite(startup_led5, LOW);    // turns the LED off
  digitalWrite(startup_led6, LOW);    // turns the LED off
  digitalWrite(special_led7, LOW);    // turns the LED off
  digitalWrite(special_led8, LOW);    // turns the LED off
  digitalWrite(special_led1, LOW);    // turns the LED off
  delay(80);
  }
 
  //////////////////////////////////////////////////////////////// 
 for (int i=0;i<255;i++)
 {
  brightness = brightness ++;
  analogWrite(special_led1, brightness);
  delay(10);
  }
 analogWrite(special_led1, 255);
  for (int i=255;i>0;i--)
 {
  brightness --;
  analogWrite(special_led1, brightness);
  delay(10);
  }
 
  for (int i=0;i<255;i++)
 {
  brightness = brightness ++;
  analogWrite(special_led7, brightness);
  analogWrite(special_led8, brightness);
  delay(10);
  }
  
  analogWrite(special_led7, 255);
  analogWrite(special_led8, 255);
 
  for (int i=255;i>0;i--)
 {
  brightness --;
  analogWrite(special_led7, brightness);
  analogWrite(special_led8, brightness);
  delay(10);
  }
  
  starttime = millis();
  endtime   = starttime;
 
 while(brightness <= 1000)
 {
     while((endtime - starttime) <= 10000)
         {
           randON = random(90,90); //tweak these for faster blink
           randOFF = random(150,350); //tweak these for faster blink
           randLED = random(1,6);
 
               if(randLED == 1)
                  {
                     digitalWrite(startup_led1, HIGH);
                     delay(randON);
                     digitalWrite(startup_led1, LOW);
                     delay(randOFF);
                   }
 
               if(randLED == 2)
                 {
                   digitalWrite(startup_led2, HIGH);
                   delay(randON);
                   digitalWrite(startup_led2, LOW);
                   delay(randOFF);
                   }
 
                   if(randLED == 3)
                      {
                       digitalWrite(startup_led3, HIGH);
                       delay(randON);
                       digitalWrite(startup_led3, LOW);
                       delay(randOFF);
                       }
 
                   if(randLED == 4)
                     {
                     digitalWrite(startup_led4, HIGH);
                     delay(randON);
                     digitalWrite(startup_led4, LOW);
                     delay(randOFF);
                     }
 
                   if(randLED == 5)
                     {
                     digitalWrite(startup_led5, HIGH);
                     delay(randON);
                     digitalWrite(startup_led5, LOW);
                     delay(randOFF);
                     }
 
                    if(randLED == 6)
                       {
                       digitalWrite(startup_led6, HIGH);
                       delay(randON);
                       digitalWrite(startup_led6, LOW);
                       delay(randOFF);
                       endtime = millis();
                       }
 
 
          }
    }
}

Here's a link to a true random number generator library
https://code.google.com/p/avr-hardware-random-number-generation/