Pages

January 9, 2016

Nativity scene with Arduino and ALA library

Here are my last creations with Arduino and my ALA library.
An Arduino Uno board is driving a WS2812 RGB LED strip and some other LEDs through a TLC5940 chip. The full sketch is less than 100 rows of code!

Normal version




Disco version




Arduino sketch


#include "AlaLed.h"
#include "AlaLedRGB.h"

#define DAY_LEN 12000

AlaLed houses1;
AlaLed houses2;
AlaLedRgb rgbStrip;

AlaColor palRed_[] = { 0xFF0000 };
AlaPalette palRed = { 1, palRed_ };
AlaColor palBlue_[] = { 0x0000FF };
AlaPalette palBlue = { 1, palBlue_ };
AlaColor palGreen_[] = { 0x00FF00 };
AlaPalette palGreen = { 1, palGreen_ };

// RGB palette with black
AlaColor alaPalRgbBlack_[] = { 0xFF0000, 0x000000, 0x00FF00, 0x000000, 0x0000FF, 0x000000 };
AlaPalette alaPalRgbBlack = { 6, alaPalRgbBlack_ };

AlaSeq houses1Seq[] =
{
  { ALA_FADEOUT,          1000, 1000 },
  { ALA_FADEOUT,          1000, 1000 },
  { ALA_FADEOUT,          1000, 1000 },

  { ALA_PIXELSMOOTHSHIFTRIGHT,  800, DAY_LEN },
  { ALA_PIXELSMOOTHBOUNCE,1000, DAY_LEN },
  { ALA_STROBO,            400, DAY_LEN },
  { ALA_SPARKLE,           800, DAY_LEN },
  
  { ALA_STROBO,           1000, 3000 },
  { ALA_FADEOUT,          1000, 1000 },
  { ALA_OFF,              5000, 5000 },
  { ALA_ENDSEQ,              0,    0 }
};

AlaSeq houses2Seq[] =
{
  { ALA_FADEOUT,          1000, 1000 },
  { ALA_FADEOUT,          1000, 1000 },
  { ALA_FADEOUT,          1000, 1000 },

  { ALA_GLOW,              800, DAY_LEN },
  { ALA_SPARKLE2,          500, DAY_LEN },
  { ALA_STROBO,            400, DAY_LEN },
  { ALA_SPARKLE,           1000, DAY_LEN },
  
  { ALA_STROBO,           1000, 3000 },
  { ALA_FADEOUT,          1000, 1000 },
  { ALA_OFF,              5000, 5000 },
  { ALA_ENDSEQ,              0,    0 }
};

AlaSeq rgbStripSeq[] =
{
  { ALA_FADEOUT,          1000, 1000, palRed },
  { ALA_FADEOUT,          1000, 1000, palBlue },
  { ALA_FADEOUT,          1000, 1000, palGreen },

  { ALA_MOVINGGRADIENT,   2000, DAY_LEN, alaPalRgbBlack },
  { ALA_LARSONSCANNER,    3000, DAY_LEN, palBlue },
  { ALA_LARSONSCANNER2,    800, DAY_LEN, palRed },
  { ALA_SPARKLE,          3000, DAY_LEN, alaPalParty },

  { ALA_STROBO,           1000, 3000, palBlue },
  { ALA_FADEOUT,          1000, 1000, palBlue },
  { ALA_OFF,              5000, 5000 },
  { ALA_ENDSEQ,              0,    0 }
};

byte houses1Pin[] = { 1,3,4,2 };
byte houses2Pin[] = { 5,6,7,8,9,10, 11,12,13,14 };
byte rgbStripPin = 2;


void setup()
{
  houses1.initTLC5940(4, houses1Pin);
  houses1.setAnimation(houses1Seq);
  
  houses2.initTLC5940(10, houses2Pin);
  houses2.setAnimation(houses2Seq);
  
  rgbStrip.initWS2812(50, rgbStripPin);
  rgbStrip.setBrightness(0x888888);
  rgbStrip.setAnimation(rgbStripSeq);
}

void loop()
{
  houses1.runAnimation();
  houses2.runAnimation();
  rgbStrip.runAnimation();
}