ALA Example - MultiLedSequence

This example of the ALA (Arduino Light Animation) library is showing how to create a sequence of animations for 5 LEDs driven by Arduino's PWM outputs.
Checkout this small video to see how the animations look like.

video


Schematic






Code


I have designed the ALA library with simplicity in mind.
You just need to initialize the AlaLed object in the setup function passing the number of LEDs you want to drive. Then you call the runAnimation method passing an array of triplets to describe the desired animation sequence. Finally you have to call the runAnimation method in the loop function to animate your LEDs.
The tricky part is the AlaSeq structure that is made by 3 fields:

  1. A numeric code identifying the desired animation. Valid codes are listed in the Ala.h header file.
  2. The animation loop duration in milliseconds.
  3. The animation total duration in milliseconds.

The last entry in the array must be ALA_ENDSEQ to close the animation sequence.

#include "AlaLed.h"

AlaLed leds;
byte pins[] = { 5, 6, 9, 10, 11 };

AlaSeq seq[] =
{
  { ALA_FADEIN, 1000, 1000 },
  { ALA_ON, 1000, 1000 },
  { ALA_FADEOUT, 1000, 1000 },
  { ALA_BARSHIFTRIGHT, 1000, 1000 },
  { ALA_BARSHIFTLEFT, 1000, 1000 },
  { ALA_OFF, 1000, 1000 },
  { ALA_PIXELSHIFTRIGHT, 700, 1400 },
  { ALA_PIXELSHIFTLEFT, 700, 1400 },
  { ALA_BLINKALT, 500, 3000 },
  { ALA_PIXELSMOOTHSHIFTRIGHT, 1000, 4000 },
  { ALA_PIXELSMOOTHSHIFTLEFT, 1000, 4000 },
  { ALA_FADEINOUT, 1000, 4000 },
  { ALA_COMET, 1000, 4000 },
  { ALA_GLOW, 1000, 4000 },
  { ALA_STROBO, 200, 4000 },
  { ALA_ENDSEQ, 0, 0 }
};


void setup()
{
  leds.initPWM(5, pins);
  leds.setAnimation(seq);
}

void loop()
{
  leds.runAnimation();
}


6 comments:

  1. Hello, i have a problem, I tried to run this code, it compile but the leds does not switch on, I check the connection and everything works fine, could you help me? IDE: 1.6.5 Arduino UNO R3

    ReplyDelete
  2. Please fix the code... really want to try out this program :)

    ReplyDelete
  3. Hi all.
    I have fixed the library.
    Please download version 2.3 and it should work.

    ReplyDelete
  4. It worked for me :) Thanks for the code

    ReplyDelete