diff --git a/examples/MultiAnimations/MultiAnimations.ino b/examples/MultiAnimations/MultiAnimations.ino index bbc82ca..0656946 100644 --- a/examples/MultiAnimations/MultiAnimations.ino +++ b/examples/MultiAnimations/MultiAnimations.ino @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////////////////// // -// ALA library example: ALA Example - ComplexMultitasking +// ALA library example: MultiAnimations // // Example to demonstrate how to drive different set of LEDs independently // using Arduino PWM output pins a TLC5940 chip and an WS2812 strip. @@ -9,8 +9,8 @@ // /////////////////////////////////////////////////////////////////////////////////////////// -#include "AlaLed.h" -#include "AlaLedRgb.h" +#include +#include byte tlcPins1[] = { 1, 2, 3 }; byte tlcPins2[] = { 6,7,8, 9,10,11, 12,13,14 }; @@ -45,3 +45,4 @@ void loop() rgbLeds.runAnimation(); rgbStrip.runAnimation(); } + diff --git a/examples/MultiLedSequence/MultiLedSequence.ino b/examples/MultiLedSequence/MultiLedSequence.ino index 530ee67..eb73a97 100644 --- a/examples/MultiLedSequence/MultiLedSequence.ino +++ b/examples/MultiLedSequence/MultiLedSequence.ino @@ -11,8 +11,16 @@ #include AlaLed leds; + +// pins where the leds are connected byte pins[] = { 5, 6, 9, 10, 11 }; +// declare the animation sequence +// each row has three values: +// 1 - a numeric code identifying the desired animation, valid codes are listed in the Ala.h +// 2 - the duration of the loop animationin milliseconds +// 3 - the total duration of the animation in milliseconds + AlaSeq seq[] = { { ALA_FADEIN, 1000, 1000 }, @@ -36,11 +44,15 @@ AlaSeq seq[] = void setup() { - leds.initPWM(3, pins); + // initialize the 5 leds attached to PWM pins + leds.initPWM(5, pins); + + // set the animation sequence leds.setAnimation(seq); } void loop() { + // run the animation leds.runAnimation(); } diff --git a/examples/RgbLedSequence/RgbLedSequence.ino b/examples/RgbLedSequence/RgbLedSequence.ino index 4abd611..d17d948 100644 --- a/examples/RgbLedSequence/RgbLedSequence.ino +++ b/examples/RgbLedSequence/RgbLedSequence.ino @@ -5,7 +5,7 @@ // Example to demonstrate how to create an animation sequence for one RGB LED. // The example also shows how to create and use a custom color palette. // -// Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbledsequence.html +// Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbledseq.html // /////////////////////////////////////////////////////////////////////////////////////////// @@ -17,21 +17,21 @@ AlaLedRgb rgbLed; -// custom palette : black , white , black , red , green , blue +// custom palette : black white black red green blue AlaColor mycolors_[6] = { 0x000000, 0xFFFFFF, 0x000000, 0xFF0000, 0x00FF00, 0x0000FF }; AlaPalette mycolors = { 6, mycolors_ }; AlaSeq seq[] = { - { ALA_CYCLECOLORS, 3000, alaPalRgb, 3000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_FADECOLORSLOOP, 4000, alaPalRgb, 8000 }, - { ALA_FADECOLORSLOOP, 500, mycolors, 4000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_FADECOLORS, 5000, mycolors, 5000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_ENDSEQ, 0, alaPalNull, 0 } + { ALA_CYCLECOLORS, 3000, 3000, alaPalRgb }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_FADECOLORSLOOP, 4000, 8000, alaPalRgb }, + { ALA_FADECOLORSLOOP, 500, 4000, mycolors }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_FADECOLORS, 5000, 5000, mycolors }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_ENDSEQ } }; @@ -50,3 +50,4 @@ void loop() { rgbLed.runAnimation(); } + diff --git a/examples/AlaRgbStripDemo/AlaRgbStripDemo.ino b/examples/RgbStripButton/RgbStripButton.ino similarity index 66% rename from examples/AlaRgbStripDemo/AlaRgbStripDemo.ino rename to examples/RgbStripButton/RgbStripButton.ino index 459cd72..8e82f4d 100644 --- a/examples/AlaRgbStripDemo/AlaRgbStripDemo.ino +++ b/examples/RgbStripButton/RgbStripButton.ino @@ -1,6 +1,20 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +// +// ALA library example: RgbStripButton +// +// Example to demonstrate how to switch animations using three buttons. +// The first button change the animation. +// The second button the color palette. +// The third button change the animation speed. +// +// Button library is required: http://playground.arduino.cc/Code/Button +// +// Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbstripbutton.html +// +/////////////////////////////////////////////////////////////////////////////////////////// -#include "AlaLedRgb.h" -#include "Button.h" +#include +#include AlaLedRgb rgbStrip; @@ -82,3 +96,4 @@ void updateAnimation() { rgbStrip.setAnimation(animList[animation%14], durationList[duration%3], paletteList[palette%3]); } + diff --git a/examples/RgbStripDemo/RgbStripDemo.ino b/examples/RgbStripDemo/RgbStripDemo.ino deleted file mode 100644 index 5d5e82d..0000000 --- a/examples/RgbStripDemo/RgbStripDemo.ino +++ /dev/null @@ -1,65 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////// -// -// ALA library example: RgbStripDemo -// -// Example to demonstrate how to create an animation sequence for a -// WS2812 RGB LED strip. -// -// Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbstripdemo.html -// -/////////////////////////////////////////////////////////////////////////////////////////// - -#include "AlaLedRgb.h" - -AlaLedRgb rgbStrip; - - -AlaSeq seq[] = -{ - { ALA_OFF, 1000, alaPalNull, 2000 }, - { ALA_ON, 1000, alaPalRgb, 2000 }, - { ALA_SPARKLE, 1000, alaPalRgb, 9000 }, - { ALA_CYCLECOLORS, 3000, alaPalRgb, 6000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_FADECOLORSLOOP, 3000, alaPalRgb, 6000 }, - { ALA_SPARKLE2, 1000, alaPalRgb, 6000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_SPARKLE2, 1000, alaPalFire, 6000 }, - { ALA_PIXELSMOOTHSHIFTRIGHT, 2000, alaPalRgb, 6000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_MOVINGBARS, 3000, alaPalRgb, 6000 }, - { ALA_COMET, 3000, alaPalRgb, 6000 }, - { ALA_COMETCOL, 3000, alaPalRgb, 6000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_GLOW, 3000, alaPalRgb, 6000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_FIRE, 1000, alaPalFire, 6000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_BOUNCINGBALLS, 1000, alaPalRgb, 6000 }, - { ALA_OFF, 1000, alaPalNull, 1000 }, - { ALA_BUBBLES, 1000, alaPalRainbow, 6000 }, - { ALA_ENDSEQ, 0, NULL, 0 } -}; -/* -AlaPalette paletteList[3] = { - alaPalRgb, - alaPalRainbow, - alaPalFire -}; -*/ -void setup() -{ - delay(1000); - - rgbStrip.initWS2812(60, 6); - - rgbStrip.setBrightness(0x444444); - - rgbStrip.setAnimation(seq); -} - -void loop() -{ - rgbStrip.runAnimation(); -} - diff --git a/examples/RgbStripSequence/RgbStripSequence.ino b/examples/RgbStripSequence/RgbStripSequence.ino new file mode 100644 index 0000000..aa800be --- /dev/null +++ b/examples/RgbStripSequence/RgbStripSequence.ino @@ -0,0 +1,60 @@ +/////////////////////////////////////////////////////////////////////////////////////////// +// +// ALA library example: RgbStripSequence +// +// Example to demonstrate how to create an animation sequence for a +// WS2812 RGB LED strip. +// +// Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbstripseq.html +// +/////////////////////////////////////////////////////////////////////////////////////////// + +#include + +AlaLedRgb rgbStrip; + + +AlaSeq seq[] = +{ + { ALA_OFF, 1000, 2000, alaPalNull }, + { ALA_ON, 1000, 2000, alaPalRgb }, + { ALA_SPARKLE, 1000, 9000, alaPalRgb }, + { ALA_CYCLECOLORS, 3000, 6000, alaPalRgb }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_FADECOLORSLOOP, 3000, 6000, alaPalRgb }, + { ALA_SPARKLE2, 1000, 6000, alaPalRgb }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_SPARKLE2, 1000, 6000, alaPalFire }, + { ALA_PIXELSMOOTHSHIFTRIGHT, 6000, 2000, alaPalRgb }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_MOVINGBARS, 3000, 6000, alaPalRgb }, + { ALA_COMET, 3000, 6000, alaPalRgb }, + { ALA_COMETCOL, 3000, 6000, alaPalRgb }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_GLOW, 3000, 6000, alaPalRgb }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_FIRE, 1000, 6000, alaPalFire }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_BOUNCINGBALLS, 1000, 6000, alaPalRgb }, + { ALA_OFF, 1000, 1000, alaPalNull }, + { ALA_BUBBLES, 1000, 6000, alaPalRainbow }, + { ALA_ENDSEQ } +}; + + +void setup() +{ + delay(1000); + + rgbStrip.initWS2812(60, 6); + + rgbStrip.setBrightness(0x444444); + + rgbStrip.setAnimation(seq); +} + +void loop() +{ + rgbStrip.runAnimation(); +} + diff --git a/examples/SimpleLed/SimpleLed.ino b/examples/SimpleLed/SimpleLed.ino index 6e8a35d..f1aa84c 100644 --- a/examples/SimpleLed/SimpleLed.ino +++ b/examples/SimpleLed/SimpleLed.ino @@ -8,14 +8,13 @@ // /////////////////////////////////////////////////////////////////////////////////////////// - #include AlaLed alaLed; void setup() { - // initialize the led attached to pin 11 + // initialize the led attached to pin 11 with PWM driver alaLed.initPWM(11); // set a fading animation with a duration of 2 seconds @@ -24,6 +23,7 @@ void setup() void loop() { - // animate the led + // run the animation alaLed.runAnimation(); } + diff --git a/examples/SimpleLed/schematic/SimpleLed_bb.png b/examples/SimpleLed/schematic/SimpleLed_bb.png index dd58c47..a32b47e 100644 Binary files a/examples/SimpleLed/schematic/SimpleLed_bb.png and b/examples/SimpleLed/schematic/SimpleLed_bb.png differ diff --git a/examples/SimpleLed/schematic/SimpleLed_schem.png b/examples/SimpleLed/schematic/SimpleLed_schem.png index fc4211c..27bdf24 100644 Binary files a/examples/SimpleLed/schematic/SimpleLed_schem.png and b/examples/SimpleLed/schematic/SimpleLed_schem.png differ diff --git a/examples/SimpleRgbLed/SimpleRgbLed.ino b/examples/SimpleRgbLed/SimpleRgbLed.ino index 8aa663e..953dde6 100644 --- a/examples/SimpleRgbLed/SimpleRgbLed.ino +++ b/examples/SimpleRgbLed/SimpleRgbLed.ino @@ -27,3 +27,4 @@ void loop() { rgbLed.runAnimation(); // run the animation indefinitely } + diff --git a/examples/SimpleRgbStrip/SimpleRgbStrip.ino b/examples/SimpleRgbStrip/SimpleRgbStrip.ino index 537b884..9c6cef2 100644 --- a/examples/SimpleRgbStrip/SimpleRgbStrip.ino +++ b/examples/SimpleRgbStrip/SimpleRgbStrip.ino @@ -1,26 +1,30 @@ /////////////////////////////////////////////////////////////////////////////////////////// // -// ALA library example: RgbStrip +// ALA library example: SimpleRgbStrip // // Example to demonstrate how to create display a color-fading animation for a // WS2812 RGB LED strip. // -// Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbstrip.html +// Web page: http://yaab-arduino.blogspot.com/p/ala-example-simplergbstrip.html // /////////////////////////////////////////////////////////////////////////////////////////// -#include "AlaLedRgb.h" +#include AlaLedRgb rgbStrip; void setup() { + // initialize the WS2812 strip with 30 leds on pin 6 rgbStrip.initWS2812(30, 6); + // set a color-fading animation with a duration of 5 seconds and an RGB palette rgbStrip.setAnimation(ALA_FADECOLORSLOOP, 5000, alaPalRgb); } void loop() { + // run the animation rgbStrip.runAnimation(); } + diff --git a/examples/SimpleTlc5940/SimpleTlc5940.ino b/examples/SimpleTlc5940/SimpleTlc5940.ino index e86bb5e..4b02267 100644 --- a/examples/SimpleTlc5940/SimpleTlc5940.ino +++ b/examples/SimpleTlc5940/SimpleTlc5940.ino @@ -8,7 +8,7 @@ // /////////////////////////////////////////////////////////////////////////////////////////// -#include "AlaLed.h" +#include AlaLed alaLed; @@ -24,3 +24,4 @@ void loop() { alaLed.runAnimation(); } + diff --git a/library.properties b/library.properties index 0d290ab..31e04f9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ALA -version=2.2.0 +version=2.3 author=bportaluri maintainer=Bruno Portaluri sentence=Arduino Light Animation (ALA) is a library diff --git a/src/Ala.cpp b/src/Ala.cpp index 16a9593..769cdb5 100644 --- a/src/Ala.cpp +++ b/src/Ala.cpp @@ -1,7 +1,5 @@ #include "Ala.h" -#include "Arduino.h" - int getStep(long t0, long t, int v) { diff --git a/src/Ala.h b/src/Ala.h index 02b5dc5..22fc1e1 100644 --- a/src/Ala.h +++ b/src/Ala.h @@ -2,9 +2,9 @@ #define Ala_h #include - #include "Arduino.h" + //////////////////////////////////////////////////////////////////////////////// // Drivers @@ -65,7 +65,7 @@ //////////////////////////////////////////////////////////////////////////////// -typedef struct AlaColor +struct AlaColor { union { @@ -130,22 +130,22 @@ typedef struct AlaColor typedef enum { - Aqua=0x00FFFF, - Black = 0x000000, - Blue = 0x0000FF, - Cyan=0x00FFFF, - Gold=0xFFD700, - Gray = 0x808080, - Green=0x008000, - Lime=0x00FF00, - Magenta=0xFF00FF, - Navy=0x000080, - Olive=0x808000, - Purple=0x800080, - Red=0xFF0000, - Teal=0x008080, - White=0xFFFFFF, - Yellow=0xFFFF00 + Aqua = 0x00FFFF, + Black = 0x000000, + Blue = 0x0000FF, + Cyan = 0x00FFFF, + Gold = 0xFFD700, + Gray = 0x808080, + Green = 0x008000, + Lime = 0x00FF00, + Magenta = 0xFF00FF, + Navy = 0x000080, + Olive = 0x808000, + Purple = 0x800080, + Red = 0xFF0000, + Teal = 0x008080, + White = 0xFFFFFF, + Yellow = 0xFFFF00 } ColorCodes; } ; @@ -155,7 +155,7 @@ typedef struct AlaColor // Struct definitions //////////////////////////////////////////////////////////////////////////////// -typedef struct AlaPalette +struct AlaPalette { int numColors; AlaColor *colors; @@ -192,12 +192,12 @@ typedef struct AlaPalette }; -typedef struct AlaSeq +struct AlaSeq { int animation; long speed; - AlaPalette palette; long duration; + AlaPalette palette; }; diff --git a/src/AlaLed.cpp b/src/AlaLed.cpp index 5da4056..a33995e 100644 --- a/src/AlaLed.cpp +++ b/src/AlaLed.cpp @@ -3,14 +3,13 @@ #include "ExtTlc5940.h" - AlaLed::AlaLed() { - maxOut=255; + maxOut = 255; speed = 1000; animSeqLen = 0; - lastRefreshTime=0; - refreshMillis=1000/50; + lastRefreshTime = 0; + refreshMillis = 1000/50; } @@ -36,10 +35,8 @@ void AlaLed::initPWM(int numLeds, byte *pins) } // allocate and clear leds array - if((leds = (byte *)malloc(numLeds))) - { - memset(leds, 0, numLeds); - } + leds = (byte *)malloc(numLeds); + memset(leds, 0, numLeds); } void AlaLed::initTLC5940(int numLeds, byte *pins) @@ -49,10 +46,8 @@ void AlaLed::initTLC5940(int numLeds, byte *pins) this->pins = pins; // allocate and clear leds array - if((leds = (byte *)malloc(numLeds))) - { - memset(leds, 0, numLeds); - } + leds = (byte *)malloc(numLeds); + memset(leds, 0, numLeds); Tlc.init(0); } diff --git a/src/AlaLed.h b/src/AlaLed.h index f5ce647..07fdd64 100644 --- a/src/AlaLed.h +++ b/src/AlaLed.h @@ -1,7 +1,6 @@ #ifndef AlaLed_h #define AlaLed_h -#include "Arduino.h" #include "Ala.h" @@ -97,10 +96,10 @@ class AlaLed void flame(); - byte driver; - byte *pins; - byte *leds; - int numLeds; + byte driver; // type of led driver: ALA_PWM, ALA_TLC5940 + byte *pins; // pins where the leds are attached to + byte *leds; // array to store leds brightness values + int numLeds; // number of leds int maxOut; int refreshMillis; diff --git a/src/AlaLedRgb.cpp b/src/AlaLedRgb.cpp index 55f91bd..979751c 100644 --- a/src/AlaLedRgb.cpp +++ b/src/AlaLedRgb.cpp @@ -1,11 +1,10 @@ #include "Ala.h" #include "AlaLedRgb.h" -#include "Arduino.h" - #include "ExtNeoPixel.h" #include "ExtTlc5940.h" + Adafruit_NeoPixel *neopixels; @@ -45,10 +44,8 @@ void AlaLedRgb::initPWM(int numLeds, byte *pins) } // allocate and clear leds array - if((leds = (AlaColor *)malloc(3*numLeds))) - { - memset(leds, 0, 3*numLeds); - } + leds = (AlaColor *)malloc(3*numLeds); + memset(leds, 0, 3*numLeds); } void AlaLedRgb::initTLC5940(int numLeds, byte *pins) @@ -58,14 +55,8 @@ void AlaLedRgb::initTLC5940(int numLeds, byte *pins) this->pins = pins; // allocate and clear leds array - if(leds = (AlaColor *)malloc(3*numLeds)) - { - memset(leds, 0, 3*numLeds); - } - - //pins = (byte *)malloc(numLeds); - //for(int i=0; idriver = ALA_WS2812; this->numLeds = numLeds; - this->pins = pins; + //this->pins = pins; // allocate and clear leds array - if((leds = (AlaColor *)malloc(3*numLeds))) - { - memset(leds, 0, 3*numLeds); - } + leds = (AlaColor *)malloc(3*numLeds); + memset(leds, 0, 3*numLeds); neopixels = new Adafruit_NeoPixel(numLeds, pin, type); diff --git a/src/AlaLedRgb.h b/src/AlaLedRgb.h index f86aeba..1bcd7c9 100644 --- a/src/AlaLedRgb.h +++ b/src/AlaLedRgb.h @@ -1,7 +1,6 @@ #ifndef AlaLedRgb_h #define AlaLedRgb_h - #include "Ala.h" @@ -89,11 +88,11 @@ class AlaLedRgb void bubbles(); - byte driver; - byte *pins; - byte pin; - AlaColor *leds; - int numLeds; + byte driver; // type of led driver: ALA_PWM, ALA_TLC5940 + byte *pins; // pins where the leds are attached to + //byte pin; + AlaColor *leds; // array to store leds brightness values + int numLeds; // number of leds int animation; int currAnim;