multiflash,multi led's a little help please...

First of all let me say I am still very much on a steep learning curve here! What I am trying to achieve is to have several led's flash a couple of times before full on. I'm trying to imitate the startup of fluourescent lighting in rooms of a model building.

I have included the first part of the code, the rest up to the fourth led is just multiples of the first section with a delay between them.

Now while this works for me, it just looks so ineligent, way too many lines. Can somebody point me in the direction of simplifying it with an example for me please? I'm thinking I should be able to put parts of it into an array of some sort, but this is where I need the help.

int ledPin1 = 13;                 // LED connected to digital pin 13
int ledPin2 = 12;                 // LED connected to digital pin 12
int ledPin3 = 11;                 // LED connected to digital pin 11
int ledPin4 = 10;                 // LED connected to digital pin 10

void setup()
{
  pinMode(ledPin1, OUTPUT);      // {{{{{{}}}}}}}
  pinMode(ledPin2, OUTPUT);      // {{{{{{}}}}}}}
  pinMode(ledPin3, OUTPUT);      // sets the digital pins as output
  pinMode(ledPin4, OUTPUT);      // {{{{{{}}}}}}}
  
                                 // SEQUENCE 1
  digitalWrite(ledPin1, HIGH);   // sets the LED on
  delay(30);                     // time delay before off cycle
  digitalWrite(ledPin1, LOW);    // sets the LED off
  delay(300);                    // time delay before on cycle
  digitalWrite(ledPin1, HIGH);   // sets the LED on
  delay(40);                     // time delay before off cycle
  digitalWrite(ledPin1, LOW);    // sets the LED off
  delay(300);                    // time delay before on cycle
  digitalWrite(ledPin1, HIGH);   // sets the LED on
  delay(300);                    // time delay before off cycle
  digitalWrite(ledPin1, LOW);    // sets the LED off
  delay(200);                    // time delay before on cycle
  digitalWrite(ledPin1, HIGH);   // sets the LED on
  delay(50);                     // time delay before off cycle
  digitalWrite(ledPin1, LOW);    // sets the LED off
  delay(500);                    // time delay before on cycle
  digitalWrite(ledPin1, HIGH);   // sets the LED on
  delay(1000);                   // time delay before next sequence

      //SEQUENCE 2
  digitalWrite(ledPin2, HIGH);   // sets the LED on
  delay(30);                     // time delay before off cycle
  digitalWrite(ledPin2, LOW);    // sets the LED off

Put the delay times in an array.
Set the output HIGH.
In a for loop, wait the delay time from the array index, then toggle the output.

Where is the rest of the code? It helps to see it all.

it just looks so ineligent

Yes it is.
You want to use arrays for, both the time delay, LED number.
If you hold these values in arrays , then a for loop can just iterate through each step in the sequence.

See:- Arrays

Thanks guys, I got that, but a line of code with explanation of what each bit does for me to study would be of great help, I've been trying to follow the tutorial pages but getting nowhere fast.

I got that,

Yes?

but a line of code with explanation of what each bit does for me to study would be of great help,

How about a whole program?

/*
 * Multiple Blink - Mike Cook
 *
 * controls 8 LEDs and blinks each one at an independent rate set by
 * the value in the flashTime array
 */

int pins[] = {18, 19, 22, 23, 25, 26, 27, 28 };  // set up the 8 pins to use as outputs - these are for a mega change according to what setup you have
int flashTime[] = { 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000};  // set up the blink time of each LED
long int changeTime[] = {0, 0, 0, 0, 0, 0, 0, 0};  // array to hold when next to change the state of each LED

void setup()                    // is run once, when the sketch starts
{
  for(int i=0; i<8; i++){
  pinMode(pins[i], OUTPUT);                    // sets the digital pins as output
  changeTime[i] = millis() + flashTime[i];    // set the time for the next change
  }
}

void loop() {                    // run over and over again
   for(int i=0 ; i<8; i++){ // look at each LED timer in turn
    if(millis()>changeTime[i]) {       // it is time to change the state of the LED
        digitalWrite(pins[i], !digitalRead(pins[i]) );  // make the LED the inverse of the current state (it's the ! that inverts)
        changeTime[i] = millis() + flashTime[i];        // set the time to make the next change
    }  // end of time to change the state of the LED if statement
  }  // end of for loop looking at all the LEDs
}  // end of loop() function

Thanks for that GM.

I'm working my way through the instructional page you first put up. I need to understand how each command works and affects other parts of the sketch to know what is going on - or otherwise it just remains gobbledegook to me - Kind of like when I learned javascript years ago, I bought several books and just stayed on the same page until I fully understood what was happening.

I need to understand how each command works

You have the referance page in the IDE for that, that explains how every command works.

affects other parts of the sketch

There is nothing that affects anything going forward, so start from the beginning and read the code. That example also encapsulates the concepts in the blink without delay example of a state machine found in the IDE. It was the only code I had to hand. For a tutorial on the state machine, see State Machine

I've been reading your tutorials Mike, its sinking in slowly, but I have to say, I am gleaning more info from them than the official tutorials under the learning tab here :wink:

That is good. If their is any specific that you need to know the feel free to ask.