About Me

My photo
They never fall who never climb.

012 ARRAY BASED CONTROL OF LED FLASH SEQUENCE


012 ARRAY BASED CONTROL OF LED FLASH SEQUENCE

March 4, 2011    (See also Companion Blog )
[Go BACK to Table of Contents] [ Next Experiment ] [ Last Experiment ]

           I needed to run this circuit to show that I was not messing up either the programming or wiring when things got complicated. The idea here was to flash a series of LEDs in sequence and make them display interesting patterns. If you examine this photo, you can actually see three of the four green LEDs lit up, but fading toward the left behind the jumble of wires. Adding many more LEDs is not that complicated.


Theory:
          By assigning pin configurations using a (single-dimension) array, one should be able to control the off-on sequences of LEDs to display interesting patterns. The LEDs are arranged in a single row on the breadboard. The progress represented by this circuit is that the LEDs can be controlled without resorting to capacitors and relays.

          The two patterns I am after is the chase, one LED after another, and the loop, flashing back and forth.

Practice:
          It worked perfectly the first time. However, this was expected for two reasons. First, the circuit is really just a single circuit duplicated four times, and it could be duplicated many more, but I ran out of resistors. Two, if you examine the code below, you will see it is an array, something I can do in my sleep, having programmed my first array ten years before the PC was invented.

Conclusion:
           LED arrays are easy and not a challenge for me. However, LEDs are not the same as LCD displays, and I can already see that the limited number of output pins on the Arduino means eventually you must use arrays to control arrays, and that can get complicated.
           Later I was able to expand this layout into as many different patterns and LED combinations I could think of. I may not pursue LEDs for now, as arrays are so rudimentary for me that I don’t learn anything. One notable revelation is I now realize where all those simple electronic gadgets come from, like flashing bicycle lights. They represent the easiest type of array programming.

           Here is the breadboard:
           Here is the code:

/* Today is March 04, 2011
* Experiment "Minutes 012" LED array
* Adapted from various sources to match my equipment
* See below to cross-reference (my) files
*/

////////////////////////////////////////////////
//INITIALIZATION AND VARIABLES
// Create the array
int LEDpins[] = {2,3,4,5};
// note the array assignment as follows
// LED #0 is connected to pin 2
// LED #1 is connected to pin 3
// LED #2 is connected to pin 4
// LED #3 is connected to pin 5
int vDelayTime = 100;

///////////////////////////////////////////////
// Begin Main Program
//////////////////////////////////////////////

// This loop steps through the array LED numbers
// Note, it does not step through the PIN numbers
void setup()
{
for (int i = 0; i < 4; i = i + 1)
{
pinMode(LEDpins[i], OUTPUT);
}
}

//The following loop calls the subroutine
//If it wasn't called, the subroutine would only run once
void loop()
{
LightsInSequence();
}

// Here is the subroutine
void LightsInSequence()
{
digitalWrite(LEDpins[0],HIGH);
delay(vDelayTime);

digitalWrite(LEDpins[1],HIGH);
delay(vDelayTime);

digitalWrite(LEDpins[2],HIGH);
delay(vDelayTime);

digitalWrite(LEDpins[3],HIGH);
delay(vDelayTime);

digitalWrite(LEDpins[0],LOW);
delay(vDelayTime);

digitalWrite(LEDpins[1],LOW);
delay(vDelayTime);

digitalWrite(LEDpins[2],LOW);
delay(vDelayTime);

digitalWrite(LEDpins[3],LOW);
delay(vDelayTime);
}

////////////////////////////////////////////////////
// END MAIN PROGRAM
////////////////////////////////////////////////////

// Key entered by Anton da Bassguy 2011
// Tested March 04, 2011
//
// Complete success, plus I ran several other patterns
// by varying the pin numbers and their order.
//
// This is excellent material for studying how the
// Arduino uses arrays and subroutines!
///////////////////////////////////////////////////

Go BACK to Table of Contents
Cross reference
Schematic: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\1003 Circuit Diagram Jpegs\Schematics
Breadboard: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\1003 Circuit Diagram Jpegs\Breadboards
Sketch: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\3002 Arduino Saved Sketches