├── examples ├── SimpleLed │ ├── schematic │ │ ├── SimpleLed.fzz │ │ ├── SimpleLed_bb.png │ │ └── SimpleLed_schem.png │ └── SimpleLed.ino ├── SimpleTlc5940 │ ├── schematic │ │ ├── SimpleTlc5940.fzz │ │ ├── SimpleTlc5940_bb.png │ │ └── SimpleTlc5940_schem.png │ └── SimpleTlc5940.ino ├── RgbStripSerial │ ├── schematic │ │ ├── RgbStripSerial.fzz │ │ └── RgbStripSerial.png │ └── RgbStripSerial.ino ├── MultiLedSequence │ ├── schematic │ │ ├── MultiLedSequence.fzz │ │ ├── MultiLedSequence_bb.png │ │ └── MultiLedSequence_schem.png │ └── MultiLedSequence.ino ├── SimpleRgbStrip │ └── SimpleRgbStrip.ino ├── SimpleRgbLed │ └── SimpleRgbLed.ino ├── MultiAnimations │ └── MultiAnimations.ino ├── RgbLedSequence │ └── RgbLedSequence.ino ├── RgbStripSequence │ └── RgbStripSequence.ino ├── RgbStripButton │ └── RgbStripButton.ino └── StartStopSequence │ └── StartStopSequence.ino ├── library.properties ├── README.md ├── src ├── pinouts │ ├── Teensypp_xxx6.h │ ├── Teensy_xxU4.h │ ├── Arduino_Mega.h │ ├── ATmega_xx8.h │ ├── ATmega_xx4.h │ ├── ATmega_8.h │ └── chip_includes.h ├── ExtTlc5940.h ├── AlaLed.h ├── AlaLedRgb.h ├── Ala.cpp ├── ExtTlc5940Config.h ├── Ala.h ├── ExtNeoPixel.h ├── AlaLed.cpp ├── ExtTlc5940.cpp └── AlaLedRgb.cpp ├── keywords.txt └── LICENSE /examples/SimpleLed/schematic/SimpleLed.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/SimpleLed/schematic/SimpleLed.fzz -------------------------------------------------------------------------------- /examples/SimpleLed/schematic/SimpleLed_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/SimpleLed/schematic/SimpleLed_bb.png -------------------------------------------------------------------------------- /examples/SimpleLed/schematic/SimpleLed_schem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/SimpleLed/schematic/SimpleLed_schem.png -------------------------------------------------------------------------------- /examples/SimpleTlc5940/schematic/SimpleTlc5940.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/SimpleTlc5940/schematic/SimpleTlc5940.fzz -------------------------------------------------------------------------------- /examples/RgbStripSerial/schematic/RgbStripSerial.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/RgbStripSerial/schematic/RgbStripSerial.fzz -------------------------------------------------------------------------------- /examples/RgbStripSerial/schematic/RgbStripSerial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/RgbStripSerial/schematic/RgbStripSerial.png -------------------------------------------------------------------------------- /examples/SimpleTlc5940/schematic/SimpleTlc5940_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/SimpleTlc5940/schematic/SimpleTlc5940_bb.png -------------------------------------------------------------------------------- /examples/MultiLedSequence/schematic/MultiLedSequence.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/MultiLedSequence/schematic/MultiLedSequence.fzz -------------------------------------------------------------------------------- /examples/SimpleTlc5940/schematic/SimpleTlc5940_schem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/SimpleTlc5940/schematic/SimpleTlc5940_schem.png -------------------------------------------------------------------------------- /examples/MultiLedSequence/schematic/MultiLedSequence_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/MultiLedSequence/schematic/MultiLedSequence_bb.png -------------------------------------------------------------------------------- /examples/MultiLedSequence/schematic/MultiLedSequence_schem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bportaluri/ALA/HEAD/examples/MultiLedSequence/schematic/MultiLedSequence_schem.png -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ALA 2 | version=2.3.8 3 | author=bportaluri 4 | maintainer=Bruno Portaluri 5 | sentence=Arduino Light Animation (ALA) library 6 | paragraph=Arduino Light Animation (ALA) is a library for Arduino boards to simplify the development of light animations using LEDs and LED strips. 7 | category=Other 8 | url=https://github.com/bportaluri/ALA 9 | architectures=* -------------------------------------------------------------------------------- /examples/SimpleTlc5940/SimpleTlc5940.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: SimpleTlc5940 4 | // 5 | // Example to demonstrate how to animate few LEDs using a TLC5940 chip. 6 | // 7 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-tlc5940.html 8 | // 9 | /////////////////////////////////////////////////////////////////////////////////////////// 10 | 11 | #include 12 | 13 | AlaLed alaLed; 14 | 15 | byte pins[] = { 4, 5, 6, 7, 8 }; 16 | 17 | void setup() 18 | { 19 | alaLed.initTLC5940(5, pins); 20 | alaLed.setAnimation(ALA_GLOW, 2000); 21 | } 22 | 23 | void loop() 24 | { 25 | alaLed.runAnimation(); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /examples/SimpleLed/SimpleLed.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: SimpleLed 4 | // 5 | // A very simple example about how to fade one LED. 6 | // 7 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-simpleled.html 8 | // 9 | /////////////////////////////////////////////////////////////////////////////////////////// 10 | 11 | #include 12 | 13 | AlaLed alaLed; 14 | 15 | void setup() 16 | { 17 | // initialize the led attached to pin 11 with PWM driver 18 | alaLed.initPWM(11); 19 | 20 | // set a fading animation with a duration of 2 seconds 21 | alaLed.setAnimation(ALA_FADEIN, 2000); 22 | } 23 | 24 | void loop() 25 | { 26 | // run the animation 27 | alaLed.runAnimation(); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ALA 2 | Arduino Light Animation (ALA) is a library for Arduino boards to simplify the development of light animations using LEDs and LED strips. 3 | 4 | More details, examples and projects can be found [here](http://yaab-arduino.blogspot.com/p/ala.html). 5 | 6 | ##Features 7 | 8 | - Pure Arduino implementation. No external software is needed on the PC to design and drive light animations. 9 | - Support for monochrome LED, RGB LED, multiple LEDs and addressable RGB LED strips using **PWM output pins**, **WS2812 RGB LED strips** and **TLC5940 chips**. 10 | - Lots of cool animations ready to use. 11 | - Precise timing to allow synching animations to music. 12 | - No use of delay() to allow to drive multiple channels and lines independently. 13 | 14 | 15 | ##Contributing 16 | 17 | If you discover a bug or would like to propose a new feature, please open a new [issue](https://github.com/bportaluri/ALA/issues). 18 | -------------------------------------------------------------------------------- /examples/SimpleRgbStrip/SimpleRgbStrip.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: SimpleRgbStrip 4 | // 5 | // Example to demonstrate how to create display a color-fading animation for a 6 | // WS2812 RGB LED strip. 7 | // 8 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-simplergbstrip.html 9 | // 10 | /////////////////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include 13 | 14 | AlaLedRgb rgbStrip; 15 | 16 | void setup() 17 | { 18 | // initialize the WS2812 strip with 30 leds on pin 6 19 | rgbStrip.initWS2812(30, 6); 20 | 21 | // set a color-fading animation with a duration of 5 seconds and an RGB palette 22 | rgbStrip.setAnimation(ALA_FADECOLORSLOOP, 5000, alaPalRgb); 23 | } 24 | 25 | void loop() 26 | { 27 | // run the animation 28 | rgbStrip.runAnimation(); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /examples/SimpleRgbLed/SimpleRgbLed.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: SimpleRgbLed 4 | // 5 | // Example to demonstrate how to create a color-fading animation for one RGB LED. 6 | // 7 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-simplergbled.html 8 | // 9 | /////////////////////////////////////////////////////////////////////////////////////////// 10 | 11 | #include 12 | 13 | #define REDPIN 11 14 | #define GREENPIN 9 15 | #define BLUEPIN 10 16 | 17 | AlaLedRgb rgbLed; 18 | 19 | void setup() 20 | { 21 | rgbLed.initPWM(REDPIN, GREENPIN, BLUEPIN); // initialize output pins 22 | rgbLed.setBrightness(0x66FF44); // calibrate white 23 | rgbLed.setAnimation(ALA_FADECOLORSLOOP, 5000, alaPalRgb); // set the animation 24 | } 25 | 26 | void loop() 27 | { 28 | rgbLed.runAnimation(); // run the animation indefinitely 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/pinouts/Teensypp_xxx6.h: -------------------------------------------------------------------------------- 1 | #ifndef TLC_Teensypp_xxx6_H 2 | #define TLC_Teensypp_xxx6_H 3 | 4 | #if DATA_TRANSFER_MODE == TLC_BITBANG 5 | #error "If you want bitbang mode, insert pin defs here" 6 | #endif 7 | 8 | // MOSI (Teensy++ pin 22) -> SIN (TLC pin 26) 9 | #define TLC_MOSI_PIN 2 10 | #define TLC_MOSI_PORT PORTB 11 | #define TLC_MOSI_DDR DDRB 12 | 13 | // SCK (Teensy++ pin 21) -> SCLK (TLC pin 25) 14 | #define TLC_SCK_PIN 1 15 | #define TLC_SCK_PORT PORTB 16 | #define TLC_SCK_DDR DDRB 17 | 18 | // SS (Teensy++ pin 20) 19 | #define TLC_SS_PIN 0 20 | #define TLC_SS_DDR DDRB 21 | 22 | // OC1A (Teensy++ pin 25) -> XLAT (TLC pin 24) 23 | #define XLAT_PIN 5 24 | #define XLAT_PORT PORTB 25 | #define XLAT_DDR DDRB 26 | 27 | // OC1B (Teensy++ pin 26) -> BLANK (TLC pin 23) 28 | #define BLANK_PIN 6 29 | #define BLANK_PORT PORTB 30 | #define BLANK_DDR DDRB 31 | 32 | // OC2B (Teensy++ pin 1) -> GSCLK (TLC pin 18) 33 | #define GSCLK_PIN 1 34 | #define GSCLK_PORT PORTD 35 | #define GSCLK_DDR DDRD 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /src/pinouts/Teensy_xxU4.h: -------------------------------------------------------------------------------- 1 | #ifndef TLC_Teensy_xxU4_h 2 | #define TLC_Teensy_xxU4_h 3 | 4 | #if DATA_TRANSFER_MODE == TLC_BITBANG 5 | #error "If you want bitbang mode, insert pin defs here" 6 | #endif 7 | 8 | // MOSI (Teensy pin 2) -> SIN (TLC pin 26) 9 | #define TLC_MOSI_PIN 2 10 | #define TLC_MOSI_PORT PORTB 11 | #define TLC_MOSI_DDR DDRB 12 | 13 | // SCK (Teensy pin 1) -> SCLK (TLC pin 25) 14 | #define TLC_SCK_PIN 1 15 | #define TLC_SCK_PORT PORTB 16 | #define TLC_SCK_DDR DDRB 17 | 18 | // SS (Teensy pin 0) 19 | #define TLC_SS_PIN 0 20 | #define TLC_SS_DDR DDRB 21 | 22 | // OC1A (Teensy pin 14) -> XLAT (TLC pin 24) 23 | #define XLAT_PIN 5 24 | #define XLAT_PORT PORTB 25 | #define XLAT_DDR DDRB 26 | 27 | // OC1B (Teensy pin 15) -> BLANK (TLC pin 23) 28 | #define BLANK_PIN 6 29 | #define BLANK_PORT PORTB 30 | #define BLANK_DDR DDRB 31 | 32 | // OC3A (Teensy pin 9) -> GSCLK (TLC pin 18) 33 | #define GSCLK_PIN 6 34 | #define GSCLK_PORT PORTC 35 | #define GSCLK_DDR DDRC 36 | #define TLC_TIMER3_GSCLK 1 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /examples/MultiAnimations/MultiAnimations.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: MultiAnimations 4 | // 5 | // Example to demonstrate how to drive different set of LEDs independently 6 | // using Arduino PWM output pins a TLC5940 chip and an WS2812 strip. 7 | // 8 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-multianimations.html 9 | // 10 | /////////////////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include 13 | #include 14 | 15 | byte tlcPins1[] = { 1, 2, 3 }; 16 | byte tlcPins2[] = { 6,7,8, 9,10,11, 12,13,14 }; 17 | 18 | AlaLed led1; 19 | AlaLed led2; 20 | AlaLed someLeds; 21 | AlaLedRgb rgbLeds; 22 | AlaLedRgb rgbStrip; 23 | 24 | 25 | void setup() 26 | { 27 | led1.initPWM(5); 28 | led2.initPWM(6); 29 | someLeds.initTLC5940(3, tlcPins1); 30 | rgbLeds.initTLC5940(3, tlcPins2); 31 | rgbStrip.initWS2812(8, 2); 32 | 33 | led1.setAnimation(ALA_STROBO, 1000); 34 | led2.setAnimation(ALA_GLOW, 5000); 35 | someLeds.setAnimation(ALA_PIXELSMOOTHSHIFTLEFT, 2400); 36 | rgbLeds.setAnimation(ALA_FADECOLORSLOOP, 12000, alaPalRgb); 37 | rgbStrip.setAnimation(ALA_COMETCOL, 5000, alaPalRgb); 38 | } 39 | 40 | void loop() 41 | { 42 | led1.runAnimation(); 43 | led2.runAnimation(); 44 | someLeds.runAnimation(); 45 | rgbLeds.runAnimation(); 46 | rgbStrip.runAnimation(); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /examples/RgbLedSequence/RgbLedSequence.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: RgbLedSequence 4 | // 5 | // Example to demonstrate how to create an animation sequence for one RGB LED. 6 | // The example also shows how to create and use a custom color palette. 7 | // 8 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbledseq.html 9 | // 10 | /////////////////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include "AlaLedRgb.h" 13 | 14 | #define REDPIN 11 15 | #define GREENPIN 9 16 | #define BLUEPIN 10 17 | 18 | AlaLedRgb rgbLed; 19 | 20 | // custom palette : black white black red green blue 21 | AlaColor mycolors_[6] = { 0x000000, 0xFFFFFF, 0x000000, 0xFF0000, 0x00FF00, 0x0000FF }; 22 | AlaPalette mycolors = { 6, mycolors_ }; 23 | 24 | 25 | AlaSeq seq[] = 26 | { 27 | { ALA_CYCLECOLORS, 3000, 3000, alaPalRgb }, 28 | { ALA_OFF, 1000, 1000, alaPalNull }, 29 | { ALA_FADECOLORSLOOP, 4000, 8000, alaPalRgb }, 30 | { ALA_FADECOLORSLOOP, 500, 4000, mycolors }, 31 | { ALA_OFF, 1000, 1000, alaPalNull }, 32 | { ALA_FADECOLORS, 5000, 5000, mycolors }, 33 | { ALA_OFF, 1000, 1000, alaPalNull }, 34 | { ALA_ENDSEQ } 35 | }; 36 | 37 | 38 | void setup() 39 | { 40 | // initialize the RGB RED 41 | rgbLed.initPWM(REDPIN, GREENPIN, BLUEPIN); 42 | 43 | // set the brightness of the LED calibrating white 44 | rgbLed.setBrightness(0x66FF44); 45 | 46 | rgbLed.setAnimation(seq); 47 | } 48 | 49 | void loop() 50 | { 51 | rgbLed.runAnimation(); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /examples/MultiLedSequence/MultiLedSequence.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: MultiLedSequence 4 | // 5 | // Example to demonstrate the use of animation sequences. 6 | // 7 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-multiledseq.html 8 | // 9 | /////////////////////////////////////////////////////////////////////////////////////////// 10 | 11 | #include 12 | 13 | AlaLed leds; 14 | 15 | // pins where the leds are connected 16 | byte pins[] = { 5, 6, 9, 10, 11 }; 17 | 18 | // declare the animation sequence 19 | // each row has three values: 20 | // 1 - a numeric code identifying the desired animation, valid codes are listed in the Ala.h 21 | // 2 - the duration of the loop animationin milliseconds 22 | // 3 - the total duration of the animation in milliseconds 23 | 24 | AlaSeq seq[] = 25 | { 26 | { ALA_FADEIN, 1000, 1000 }, 27 | { ALA_ON, 1000, 1000 }, 28 | { ALA_FADEOUT, 1000, 1000 }, 29 | { ALA_BARSHIFTRIGHT, 1000, 1000 }, 30 | { ALA_BARSHIFTLEFT, 1000, 1000 }, 31 | { ALA_OFF, 1000, 1000 }, 32 | { ALA_PIXELSHIFTRIGHT, 700, 1400 }, 33 | { ALA_PIXELSHIFTLEFT, 700, 1400 }, 34 | { ALA_BLINKALT, 500, 3000 }, 35 | { ALA_PIXELSMOOTHSHIFTRIGHT, 1000, 4000 }, 36 | { ALA_PIXELSMOOTHSHIFTLEFT, 1000, 4000 }, 37 | { ALA_FADEINOUT, 1000, 4000 }, 38 | { ALA_COMET, 1000, 4000 }, 39 | { ALA_GLOW, 1000, 4000 }, 40 | { ALA_STROBO, 200, 4000 }, 41 | { ALA_ENDSEQ, 0, 0 } 42 | }; 43 | 44 | 45 | void setup() 46 | { 47 | // initialize the 5 leds attached to PWM pins 48 | leds.initPWM(5, pins); 49 | 50 | // set the animation sequence 51 | leds.setAnimation(seq); 52 | } 53 | 54 | void loop() 55 | { 56 | // run the animation 57 | leds.runAnimation(); 58 | } 59 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For ALA 3 | ####################################### 4 | 5 | 6 | ####################################### 7 | # Datatypes (KEYWORD1) 8 | ####################################### 9 | 10 | AlaLed KEYWORD1 11 | AlaLedRgb KEYWORD1 12 | 13 | AlaColor KEYWORD1 14 | AlaPalette KEYWORD1 15 | AlaSeq KEYWORD1 16 | 17 | 18 | ####################################### 19 | # Methods and Functions 20 | ####################################### 21 | 22 | initPWM KEYWORD2 23 | initTLC5940 KEYWORD2 24 | initWS2812 KEYWORD2 25 | setBrightness KEYWORD2 26 | setRefreshRate KEYWORD2 27 | setAnimation KEYWORD2 28 | runAnimation KEYWORD2 29 | 30 | 31 | ####################################### 32 | # Constants 33 | ####################################### 34 | 35 | ALA_ON LITERAL1 36 | ALA_OFF LITERAL1 37 | ALA_BLINK LITERAL1 38 | ALA_BLINKALT LITERAL1 39 | ALA_SPARKLE LITERAL1 40 | ALA_SPARKLE2 LITERAL1 41 | ALA_STROBO LITERAL1 42 | 43 | ALA_FADECOLORSLOOP LITERAL1 44 | ALA_FADECOLORS LITERAL1 45 | ALA_CYCLECOLORS LITERAL1 46 | ALA_PIXELSFADECOLORS LITERAL1 47 | 48 | ALA_PIXELSHIFTRIGHT LITERAL1 49 | ALA_PIXELSHIFTLEFT LITERAL1 50 | ALA_PIXELBOUNCE LITERAL1 51 | ALA_PIXELSMOOTHSHIFTRIGHT LITERAL1 52 | ALA_PIXELSMOOTHSHIFTLEFT LITERAL1 53 | ALA_PIXELSMOOTHBOUNCE LITERAL1 54 | ALA_COMET LITERAL1 55 | ALA_COMETCOL LITERAL1 56 | ALA_BARSHIFTRIGHT LITERAL1 57 | ALA_BARSHIFTLEFT LITERAL1 58 | ALA_LARSONSCANNER LITERAL1 59 | ALA_LARSONSCANNER2 LITERAL1 60 | ALA_MOVINGBARS LITERAL1 61 | ALA_MOVINGGRADIENT LITERAL1 62 | 63 | ALA_FADEIN LITERAL1 64 | ALA_FADEOUT LITERAL1 65 | ALA_FADEINOUT LITERAL1 66 | ALA_GLOW LITERAL1 67 | ALA_PLASMA LITERAL1 68 | 69 | ALA_FIRE LITERAL1 70 | ALA_BOUNCINGBALLS LITERAL1 71 | ALA_BUBBLES LITERAL1 72 | 73 | ALA_STOPSEQ LITERAL1 74 | ALA_ENDSEQ LITERAL1 75 | -------------------------------------------------------------------------------- /examples/RgbStripSequence/RgbStripSequence.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: RgbStripSequence 4 | // 5 | // Example to demonstrate how to create an animation sequence for a 6 | // WS2812 RGB LED strip. 7 | // 8 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbstripseq.html 9 | // 10 | /////////////////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include 13 | 14 | AlaLedRgb rgbStrip; 15 | 16 | 17 | AlaSeq seq[] = 18 | { 19 | { ALA_OFF, 1000, 2000, alaPalNull }, 20 | { ALA_ON, 1000, 2000, alaPalRgb }, 21 | { ALA_SPARKLE, 1000, 9000, alaPalRgb }, 22 | { ALA_CYCLECOLORS, 3000, 6000, alaPalRgb }, 23 | { ALA_OFF, 1000, 1000, alaPalNull }, 24 | { ALA_FADECOLORSLOOP, 3000, 6000, alaPalRgb }, 25 | { ALA_SPARKLE2, 1000, 6000, alaPalRgb }, 26 | { ALA_OFF, 1000, 1000, alaPalNull }, 27 | { ALA_SPARKLE2, 1000, 6000, alaPalFire }, 28 | { ALA_PIXELSMOOTHSHIFTRIGHT, 6000, 2000, alaPalRgb }, 29 | { ALA_OFF, 1000, 1000, alaPalNull }, 30 | { ALA_MOVINGBARS, 3000, 6000, alaPalRgb }, 31 | { ALA_COMET, 3000, 6000, alaPalRgb }, 32 | { ALA_COMETCOL, 3000, 6000, alaPalRgb }, 33 | { ALA_OFF, 1000, 1000, alaPalNull }, 34 | { ALA_GLOW, 3000, 6000, alaPalRgb }, 35 | { ALA_OFF, 1000, 1000, alaPalNull }, 36 | { ALA_FIRE, 1000, 6000, alaPalFire }, 37 | { ALA_OFF, 1000, 1000, alaPalNull }, 38 | { ALA_BOUNCINGBALLS, 1000, 6000, alaPalRgb }, 39 | { ALA_OFF, 1000, 1000, alaPalNull }, 40 | { ALA_BUBBLES, 1000, 6000, alaPalRainbow }, 41 | { ALA_ENDSEQ } 42 | }; 43 | 44 | 45 | void setup() 46 | { 47 | delay(1000); 48 | 49 | rgbStrip.initWS2812(60, 6); 50 | 51 | rgbStrip.setBrightness(0x444444); 52 | 53 | rgbStrip.setAnimation(seq); 54 | } 55 | 56 | void loop() 57 | { 58 | rgbStrip.runAnimation(); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /examples/RgbStripButton/RgbStripButton.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: RgbStripButton 4 | // 5 | // Example to demonstrate how to switch animations using three buttons. 6 | // The first button change the animation. 7 | // The second button the color palette. 8 | // The third button change the animation speed. 9 | // 10 | // Button library is required: http://playground.arduino.cc/Code/Button 11 | // 12 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbstripbutton.html 13 | // 14 | /////////////////////////////////////////////////////////////////////////////////////////// 15 | 16 | #include 17 | #include 18 | 19 | 20 | AlaLedRgb rgbStrip; 21 | Button button1 = Button(2, PULLDOWN); 22 | Button button2 = Button(3, PULLDOWN); 23 | Button button3 = Button(4, PULLDOWN); 24 | 25 | int animation = 0; 26 | int duration = 0; 27 | int palette = 0; 28 | 29 | int animList[14] = { 30 | ALA_ON, 31 | ALA_SPARKLE, 32 | ALA_SPARKLE2, 33 | ALA_PIXELSHIFTRIGHT, 34 | ALA_PIXELSMOOTHSHIFTRIGHT, 35 | ALA_MOVINGBARS, 36 | ALA_COMET, 37 | ALA_COMETCOL, 38 | ALA_GLOW, 39 | ALA_CYCLECOLORS, 40 | ALA_FADECOLORS, 41 | ALA_FIRE, 42 | ALA_BOUNCINGBALLS, 43 | ALA_BUBBLES 44 | }; 45 | 46 | AlaPalette paletteList[3] = { 47 | alaPalRgb, 48 | alaPalRainbow, 49 | alaPalFire 50 | }; 51 | 52 | int durationList[3] = { 53 | 1000, 54 | 2000, 55 | 5000 56 | }; 57 | 58 | 59 | void setup() 60 | { 61 | delay(4000); 62 | 63 | rgbStrip.initWS2812(60, 6); 64 | 65 | updateAnimation(); 66 | } 67 | 68 | void loop() 69 | { 70 | // button 1 changes the animation 71 | if (button1.uniquePress()) 72 | { 73 | animation++; 74 | updateAnimation(); 75 | } 76 | 77 | // button 2 changes the color palette 78 | if (button2.uniquePress()) 79 | { 80 | palette++; 81 | updateAnimation(); 82 | } 83 | 84 | // button 3 changes the animation speed 85 | if (button3.uniquePress()) 86 | { 87 | duration++; 88 | updateAnimation(); 89 | } 90 | 91 | rgbStrip.runAnimation(); 92 | 93 | } 94 | 95 | void updateAnimation() 96 | { 97 | rgbStrip.setAnimation(animList[animation%14], durationList[duration%3], paletteList[palette%3]); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /examples/StartStopSequence/StartStopSequence.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: StartStopSequence 4 | // 5 | // Example to demonstrate how to play an animation sequence, stop it, do something else 6 | // start a new sequence and so on. 7 | // 8 | /////////////////////////////////////////////////////////////////////////////////////////// 9 | 10 | #include 11 | 12 | AlaLedRgb rgbStrip; 13 | 14 | int animPhase = 0; 15 | 16 | // define the sequences to use 17 | 18 | AlaSeq seq1[] = 19 | { 20 | { ALA_ON, 2000, 2000, alaPalRgb }, 21 | { ALA_SPARKLE, 2000, 2000, alaPalRgb }, 22 | { ALA_CYCLECOLORS, 2000, 2000, alaPalRgb }, 23 | { ALA_STOPSEQ, 1000, 1000, alaPalNull }, 24 | { ALA_ENDSEQ } 25 | }; 26 | 27 | AlaSeq seq2[]= 28 | { 29 | { ALA_FADECOLORSLOOP, 3000, 4000, alaPalRgb }, 30 | { ALA_COMETCOL, 3000, 4000, alaPalRgb }, 31 | { ALA_SPARKLE2, 1000, 4000, alaPalRgb }, 32 | { ALA_STOPSEQ, 1000, 1000, alaPalNull }, 33 | { ALA_ENDSEQ } 34 | }; 35 | 36 | AlaSeq seq3[]= 37 | { 38 | { ALA_GLOW, 3000, 4000, alaPalRgb }, 39 | { ALA_OFF, 1000, 1000, alaPalNull }, 40 | { ALA_BOUNCINGBALLS, 1000, 4000, alaPalRgb }, 41 | { ALA_STOPSEQ, 1000, 1000, alaPalNull }, 42 | { ALA_ENDSEQ } 43 | }; 44 | 45 | 46 | void setup() 47 | { 48 | Serial.begin(9600); 49 | delay(100); // some arduinos need it 50 | 51 | Serial.println("\nAnimation sequences starting\n"); 52 | 53 | // 10 leds driven by pin 6 54 | rgbStrip.initWS2812(10, 6); 55 | rgbStrip.setBrightness(0x444444); 56 | 57 | rgbStrip.setAnimation(seq1); 58 | animPhase = 1; 59 | } 60 | 61 | void loop() 62 | { 63 | rgbStrip.runAnimation(); 64 | 65 | if(animPhase==1 && rgbStrip.getAnimation()==ALA_STOPSEQ) 66 | { 67 | Serial.println("\nSequence 1 completed"); 68 | // do something here 69 | for(int i=0;i<30;i++) 70 | { 71 | Serial.print("1"); 72 | delay(100); 73 | } 74 | rgbStrip.setAnimation(seq2); 75 | animPhase = 2; 76 | } 77 | if(animPhase==2 && rgbStrip.getAnimation()==ALA_STOPSEQ) 78 | { 79 | Serial.println("\nSequence 2 completed"); 80 | for(int i=0;i<30;i++) 81 | { 82 | Serial.print("2"); 83 | delay(100); 84 | } 85 | rgbStrip.setAnimation(seq3); 86 | animPhase = 3; 87 | } 88 | if(animPhase==3 && rgbStrip.getAnimation()==ALA_STOPSEQ) 89 | { 90 | Serial.println("\nSequence 3 completed"); 91 | animPhase = 4; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/ExtTlc5940.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC5940_H 20 | #define TLC5940_H 21 | 22 | /** \file 23 | Tlc5940 library header file. */ 24 | 25 | #include 26 | #include "ExtTlc5940Config.h" 27 | 28 | #ifdef TLC_ATMEGA_8_H 29 | 30 | /** Enables the Timer1 Overflow interrupt, which will fire after an XLAT 31 | pulse */ 32 | #define set_XLAT_interrupt() TIFR |= _BV(TOV1); TIMSK = _BV(TOIE1) 33 | /** Disables any Timer1 interrupts */ 34 | #define clear_XLAT_interrupt() TIMSK = 0 35 | 36 | #else 37 | 38 | /** Enables the Timer1 Overflow interrupt, which will fire after an XLAT 39 | pulse */ 40 | #define set_XLAT_interrupt() TIFR1 |= _BV(TOV1); TIMSK1 = _BV(TOIE1) 41 | /** Disables any Timer1 interrupts */ 42 | #define clear_XLAT_interrupt() TIMSK1 = 0 43 | 44 | #endif 45 | 46 | /** Enables the output of XLAT pulses */ 47 | #define enable_XLAT_pulses() TCCR1A = _BV(COM1A1) | _BV(COM1B1) 48 | /** Disables the output of XLAT pulses */ 49 | #define disable_XLAT_pulses() TCCR1A = _BV(COM1B1) 50 | 51 | extern volatile uint8_t tlc_needXLAT; 52 | extern volatile void (*tlc_onUpdateFinished)(void); 53 | extern uint8_t tlc_GSData[NUM_TLCS * 24]; 54 | 55 | /** The main Tlc5940 class for the entire library. An instance of this class 56 | will be preinstantiated as Tlc. */ 57 | class Tlc5940 58 | { 59 | public: 60 | void init(uint16_t initialValue = 0); 61 | void clear(void); 62 | uint8_t update(void); 63 | void set(TLC_CHANNEL_TYPE channel, uint16_t value); 64 | uint16_t get(TLC_CHANNEL_TYPE channel); 65 | void setAll(uint16_t value); 66 | #if VPRG_ENABLED 67 | void setAllDC(uint8_t value); 68 | #endif 69 | #if XERR_ENABLED 70 | uint8_t readXERR(void); 71 | #endif 72 | 73 | }; 74 | 75 | void tlc_shift8_init(void); 76 | void tlc_shift8(uint8_t byte); 77 | 78 | #if VPRG_ENABLED 79 | void tlc_dcModeStart(void); 80 | void tlc_dcModeStop(void); 81 | #endif 82 | 83 | // for the preinstantiated Tlc variable. 84 | extern Tlc5940 Tlc; 85 | 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /src/pinouts/Arduino_Mega.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef ARDUINO_MEGA_H 20 | #define ARDUINO_MEGA_H 21 | 22 | /** \file 23 | SPI and timer pins for the Arduino Mega. Don't edit these. All 24 | changeable pins are defined in tlc_config.h */ 25 | 26 | /** VPRG (Mega pin 50) -> VPRG (TLC pin 27) */ 27 | #define DEFAULT_VPRG_PIN PB3 28 | #define DEFAULT_VPRG_PORT PORTB 29 | #define DEFAULT_VPRG_DDR DDRB 30 | 31 | /** XERR (Mega pin 10) -> XERR (TLC pin 16) */ 32 | #define DEFAULT_XERR_PIN PB4 33 | #define DEFAULT_XERR_PORT PORTB 34 | #define DEFAULT_XERR_DDR DDRB 35 | #define DEFAULT_XERR_PINS PINB 36 | 37 | /** SIN (Mega pin 51) -> SIN (TLC pin 26) */ 38 | #define DEFAULT_BB_SIN_PIN PB2 39 | #define DEFAULT_BB_SIN_PORT PORTB 40 | #define DEFAULT_BB_SIN_DDR DDRB 41 | /** SCLK (Mega pin 52) -> SCLK (TLC pin 25) */ 42 | #define DEFAULT_BB_SCLK_PIN PB1 43 | #define DEFAULT_BB_SCLK_PORT PORTB 44 | #define DEFAULT_BB_SCLK_DDR DDRB 45 | 46 | /** MOSI (Mega pin 51) -> SIN (TLC pin 26) */ 47 | #define TLC_MOSI_PIN PB2 48 | #define TLC_MOSI_PORT PORTB 49 | #define TLC_MOSI_DDR DDRB 50 | 51 | /** SCK (Mega pin 52) -> SCLK (TLC pin 25) */ 52 | #define TLC_SCK_PIN PB1 53 | #define TLC_SCK_PORT PORTB 54 | #define TLC_SCK_DDR DDRB 55 | 56 | // SS (Mega pin 53) 57 | /** SS will be set to output as to not interfere with SPI master operation. 58 | If you have changed the pin-outs and the library doesn't seem to work 59 | or works intermittently, make sure this pin is set correctly. This pin 60 | will not be used by the library other than setting its direction to 61 | output. */ 62 | #define TLC_SS_PIN PB0 63 | #define TLC_SS_DDR DDRB 64 | 65 | /** OC1A (Mega pin 11) -> XLAT (TLC pin 24) */ 66 | #define XLAT_PIN PB5 67 | #define XLAT_PORT PORTB 68 | #define XLAT_DDR DDRB 69 | 70 | /** OC1B (Mega pin 12) -> BLANK (TLC pin 23) */ 71 | #define BLANK_PIN PB6 72 | #define BLANK_PORT PORTB 73 | #define BLANK_DDR DDRB 74 | 75 | /** OC2B (Mega pin 9) -> GSCLK (TLC pin 18) */ 76 | #define GSCLK_PIN PH6 77 | #define GSCLK_PORT PORTH 78 | #define GSCLK_DDR DDRH 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /src/pinouts/ATmega_xx8.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_ATMEGA_XX8_H 20 | #define TLC_ATMEGA_XX8_H 21 | 22 | /** \file 23 | SPI and timer pins for the ATmega168/48/88. Don't edit these. All 24 | changeable pins are defined in tlc_config.h */ 25 | 26 | /** VPRG (Arduino digital pin 8) -> VPRG (TLC pin 27) */ 27 | #define DEFAULT_VPRG_PIN PB0 28 | #define DEFAULT_VPRG_PORT PORTB 29 | #define DEFAULT_VPRG_DDR DDRB 30 | 31 | /** XERR (Arduino digital pin 12) -> XERR (TLC pin 16) */ 32 | #define DEFAULT_XERR_PIN PB4 33 | #define DEFAULT_XERR_PORT PORTB 34 | #define DEFAULT_XERR_DDR DDRB 35 | #define DEFAULT_XERR_PINS PINB 36 | 37 | /** SIN (Arduino digital pin 7) -> SIN (TLC pin 26) */ 38 | #define DEFAULT_BB_SIN_PIN PD7 39 | #define DEFAULT_BB_SIN_PORT PORTD 40 | #define DEFAULT_BB_SIN_DDR DDRD 41 | /** SCLK (Arduino digital pin 4) -> SCLK (TLC pin 25) */ 42 | #define DEFAULT_BB_SCLK_PIN PD4 43 | #define DEFAULT_BB_SCLK_PORT PORTD 44 | #define DEFAULT_BB_SCLK_DDR DDRD 45 | 46 | /** MOSI (Arduino digital pin 11) -> SIN (TLC pin 26) */ 47 | #define TLC_MOSI_PIN PB3 48 | #define TLC_MOSI_PORT PORTB 49 | #define TLC_MOSI_DDR DDRB 50 | 51 | /** SCK (Arduino digital pin 13) -> SCLK (TLC pin 25) */ 52 | #define TLC_SCK_PIN PB5 53 | #define TLC_SCK_PORT PORTB 54 | #define TLC_SCK_DDR DDRB 55 | 56 | /** SS will be set to output as to not interfere with SPI master operation. 57 | If you have changed the pin-outs and the library doesn't seem to work 58 | or works intermittently, make sure this pin is set correctly. This pin 59 | will not be used by the library other than setting its direction to 60 | output. */ 61 | #define TLC_SS_PIN PB2 62 | #define TLC_SS_DDR DDRB 63 | 64 | /** OC1A (Arduino digital pin 9) -> XLAT (TLC pin 24) */ 65 | #define XLAT_PIN PB1 66 | #define XLAT_PORT PORTB 67 | #define XLAT_DDR DDRB 68 | 69 | /** OC1B (Arduino digital pin 10) -> BLANK (TLC pin 23) */ 70 | #define BLANK_PIN PB2 71 | #define BLANK_PORT PORTB 72 | #define BLANK_DDR DDRB 73 | 74 | /** OC2B (Arduino digital pin 3) -> GSCLK (TLC pin 18) */ 75 | #define GSCLK_PIN PD3 76 | #define GSCLK_PORT PORTD 77 | #define GSCLK_DDR DDRD 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /src/pinouts/ATmega_xx4.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_ATMEGA_XX8_H 20 | #define TLC_ATMEGA_XX8_H 21 | 22 | /** \file 23 | SPI and timer pins for the ATmega164/324/644. Don't edit these. All 24 | changeable pins are defined in tlc_config.h */ 25 | 26 | /** VPRG (Sanguino digital pin 15) -> VPRG (TLC pin 27) */ 27 | #define DEFAULT_VPRG_PIN PD7 28 | #define DEFAULT_VPRG_PORT PORTD 29 | #define DEFAULT_VPRG_DDR DDRD 30 | 31 | /** XERR (Sanguino digital pin 6) -> XERR (TLC pin 16) */ 32 | #define DEFAULT_XERR_PIN PB6 33 | #define DEFAULT_XERR_PORT PORTB 34 | #define DEFAULT_XERR_DDR DDRB 35 | #define DEFAULT_XERR_PINS PINB 36 | 37 | /** SIN (Sanguino digital pin 5) -> SIN (TLC pin 26) */ 38 | #define DEFAULT_BB_SIN_PIN PB5 39 | #define DEFAULT_BB_SIN_PORT PORTB 40 | #define DEFAULT_BB_SIN_DDR DDRB 41 | /** SCLK (Sanguino digital pin 7) -> SCLK (TLC pin 25) */ 42 | #define DEFAULT_BB_SCLK_PIN PB7 43 | #define DEFAULT_BB_SCLK_PORT PORTB 44 | #define DEFAULT_BB_SCLK_DDR DDRB 45 | 46 | /** MOSI (Sanguino digital pin 5) -> SIN (TLC pin 26) */ 47 | #define TLC_MOSI_PIN PB5 48 | #define TLC_MOSI_PORT PORTB 49 | #define TLC_MOSI_DDR DDRB 50 | 51 | /** SCK (Sanguino digital pin 7) -> SCLK (TLC pin 25) */ 52 | #define TLC_SCK_PIN PB7 53 | #define TLC_SCK_PORT PORTB 54 | #define TLC_SCK_DDR DDRB 55 | 56 | /** SS will be set to output as to not interfere with SPI master operation. 57 | If you have changed the pin-outs and the library doesn't seem to work 58 | or works intermittently, make sure this pin is set correctly. This pin 59 | will not be used by the library other than setting its direction to 60 | output. */ 61 | #define TLC_SS_PIN PB4 62 | #define TLC_SS_DDR DDRB 63 | 64 | /** OC1A (Sanguino digital pin 13) -> XLAT (TLC pin 24) */ 65 | #define XLAT_PIN PD5 66 | #define XLAT_PORT PORTD 67 | #define XLAT_DDR DDRD 68 | 69 | /** OC1B (Sanguino digital pin 12) -> BLANK (TLC pin 23) */ 70 | #define BLANK_PIN PD4 71 | #define BLANK_PORT PORTD 72 | #define BLANK_DDR DDRD 73 | 74 | /** OC2B (Sanguino digital pin 14) -> GSCLK (TLC pin 18) */ 75 | #define GSCLK_PIN PD6 76 | #define GSCLK_PORT PORTD 77 | #define GSCLK_DDR DDRD 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /src/pinouts/ATmega_8.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_ATMEGA_8_H 20 | #define TLC_ATMEGA_8_H 21 | 22 | #if DATA_TRANSFER_MODE == TLC_SPI 23 | #warning SPI cannot be used on the ATmega8 because it interferes with timer2 24 | #warning setting DATA_TRANSFER_MODE to TLC_BITBANG 25 | #define DATA_TRANSFER_MODE TLC_BITBANG 26 | #endif 27 | 28 | /** \file 29 | SPI and timer pins for the ATmega8. Don't edit these. All 30 | changeable pins are defined in tlc_config.h */ 31 | 32 | /** VPRG (Arduino digital pin 8) -> VPRG (TLC pin 27) */ 33 | #define DEFAULT_VPRG_PIN PB0 34 | #define DEFAULT_VPRG_PORT PORTB 35 | #define DEFAULT_VPRG_DDR DDRB 36 | 37 | /** XERR (Arduino digital pin 12) -> XERR (TLC pin 16) */ 38 | #define DEFAULT_XERR_PIN PB4 39 | #define DEFAULT_XERR_PORT PORTB 40 | #define DEFAULT_XERR_DDR DDRB 41 | #define DEFAULT_XERR_PINS PINB 42 | 43 | /** SIN (Arduino digital pin 7) -> SIN (TLC pin 26) */ 44 | #define DEFAULT_BB_SIN_PIN PD7 45 | #define DEFAULT_BB_SIN_PORT PORTD 46 | #define DEFAULT_BB_SIN_DDR DDRD 47 | /** SCLK (Arduino digital pin 4) -> SCLK (TLC pin 25) */ 48 | #define DEFAULT_BB_SCLK_PIN PD4 49 | #define DEFAULT_BB_SCLK_PORT PORTD 50 | #define DEFAULT_BB_SCLK_DDR DDRD 51 | 52 | /** MOSI (Arduino digital pin 11) -> SIN (TLC pin 26) */ 53 | #define TLC_MOSI_PIN PB3 54 | #define TLC_MOSI_PORT PORTB 55 | #define TLC_MOSI_DDR DDRB 56 | 57 | /** SCK (Arduino digital pin 13) -> SCLK (TLC pin 25) */ 58 | #define TLC_SCK_PIN PB5 59 | #define TLC_SCK_PORT PORTB 60 | #define TLC_SCK_DDR DDRB 61 | 62 | /** SS will be set to output as to not interfere with SPI master operation. 63 | If you have changed the pin-outs and the library doesn't seem to work 64 | or works intermittently, make sure this pin is set correctly. This pin 65 | will not be used by the library other than setting its direction to 66 | output. */ 67 | #define TLC_SS_PIN PB2 68 | #define TLC_SS_DDR DDRB 69 | 70 | /** OC1A (Arduino digital pin 9) -> XLAT (TLC pin 24) */ 71 | #define XLAT_PIN PB1 72 | #define XLAT_PORT PORTB 73 | #define XLAT_DDR DDRB 74 | 75 | /** OC1B (Arduino digital pin 10) -> BLANK (TLC pin 23) */ 76 | #define BLANK_PIN PB2 77 | #define BLANK_PORT PORTB 78 | #define BLANK_DDR DDRB 79 | 80 | /** OC2B (Arduino digital pin 3) -> GSCLK (TLC pin 18) */ 81 | #define GSCLK_PIN PD3 82 | #define GSCLK_PORT PORTD 83 | #define GSCLK_DDR DDRD 84 | 85 | #endif 86 | 87 | -------------------------------------------------------------------------------- /src/AlaLed.h: -------------------------------------------------------------------------------- 1 | #ifndef AlaLed_h 2 | #define AlaLed_h 3 | 4 | #include "Ala.h" 5 | 6 | 7 | /** 8 | * AlaLed can be used to drive a single or multiple output channels to perform animations. 9 | * Single leds can be attached to each channel or MOSFETS/relays can be used to drive 10 | * heavier loads such as lamps or monochrome led strips. 11 | */ 12 | class AlaLed 13 | { 14 | 15 | public: 16 | 17 | AlaLed(); 18 | 19 | 20 | /** 21 | * Initializes a LED driven by Arduino PWM pin. It be invoked in the setup() function of the main Arduino sketch. 22 | */ 23 | void initPWM(byte pin); 24 | 25 | /** 26 | * Initializes LEDs driven by Arduino PWM pins. It be invoked in the setup() function of the main Arduino sketch. 27 | */ 28 | void initPWM(int numLeds, byte *pins); 29 | 30 | /** 31 | * Initializes LEDs driven by a TLC5940 chip. It be invoked in the setup() function of the main Arduino sketch. 32 | * The TLC5940 must be wired as follows (http://XYXYXYXY) 33 | * pin 2 > GND 34 | * pin 3 > Arduino 11 35 | * pin 4 > Arduino 13 36 | * pin 5 > Arduino 9 37 | * pin 6 > Arduino 10 + XXX resistor to +5V 38 | * pin 7 > GND 39 | * pin 8 > +5V 40 | * pin 9 > xxx resistor to GND 41 | * pin 10 > +5V 42 | * pin 11 > Arduino 3 43 | * 44 | * It can be used also to drive a single led. 45 | */ 46 | void initTLC5940(int numLeds, byte *pins); 47 | 48 | 49 | /** 50 | * Sets the maximum brightness level (0-255). 51 | */ 52 | void setBrightness(byte maxOut); 53 | 54 | /** 55 | * Sets the maximum refresh rate in Hz (default value is 50 Hz). 56 | * May be useful to reduce flickering in some cases. 57 | */ 58 | void setRefreshRate(int refreshRate); 59 | 60 | int getRefreshRate(); 61 | 62 | void setAnimation(int animation, long speed, bool isSeq=false); 63 | void setAnimation(AlaSeq animSeq[]); 64 | void setSpeed(long speed); 65 | int getAnimation(); 66 | 67 | bool runAnimation(); 68 | 69 | 70 | private: 71 | 72 | void setAnimationFunc(int animation); 73 | void on(); 74 | void off(); 75 | void blink(); 76 | void blinkAlt(); 77 | void sparkle(); 78 | void sparkle2(); 79 | void strobo(); 80 | 81 | void pixelShiftRight(); 82 | void pixelShiftLeft(); 83 | void pixelBounce(); 84 | void pixelSmoothShiftRight(); 85 | void pixelSmoothShiftLeft(); 86 | void pixelSmoothBounce(); 87 | void comet(); 88 | void barShiftRight(); 89 | void barShiftLeft(); 90 | void larsonScanner(); 91 | void larsonScanner2(); 92 | 93 | void fadeIn(); 94 | void fadeOut(); 95 | void fadeInOut(); 96 | void glow(); 97 | void flame(); 98 | 99 | 100 | byte driver; // type of led driver: ALA_PWM, ALA_TLC5940 101 | byte *pins; // pins where the leds are attached to 102 | byte *leds; // array to store leds brightness values 103 | int numLeds; // number of leds 104 | 105 | int maxOut; 106 | int refreshMillis; 107 | int refreshRate; // current refresh rate 108 | 109 | int animation; 110 | long speed; 111 | AlaSeq *animSeq; 112 | int animSeqLen; 113 | long animSeqDuration; 114 | 115 | void (AlaLed::*animFunc)(); 116 | unsigned long animStartTime; 117 | unsigned long animSeqStartTime; 118 | unsigned long lastRefreshTime; 119 | 120 | }; 121 | 122 | #endif -------------------------------------------------------------------------------- /src/pinouts/chip_includes.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_CHIP_INCLUDES_H 20 | #define TLC_CHIP_INCLUDES_H 21 | 22 | /** \file 23 | Includes the chip-specfic defaults and pin definitions. */ 24 | 25 | #include 26 | 27 | #ifndef PB0 28 | #define PB0 PORTB0 29 | #define PB1 PORTB1 30 | #define PB2 PORTB2 31 | #define PB3 PORTB3 32 | #define PB4 PORTB4 33 | #define PB5 PORTB5 34 | #define PB6 PORTB6 35 | #define PB7 PORTB7 36 | #endif 37 | #ifndef PC0 38 | #define PC0 PORTC0 39 | #define PC1 PORTC1 40 | #define PC2 PORTC2 41 | #define PC3 PORTC3 42 | #define PC4 PORTC4 43 | #define PC5 PORTC5 44 | #define PC6 PORTC6 45 | #define PC7 PORTC7 46 | #endif 47 | #ifndef PD0 48 | #define PD0 PORTD0 49 | #define PD1 PORTD1 50 | #define PD2 PORTD2 51 | #define PD3 PORTD3 52 | #define PD4 PORTD4 53 | #define PD5 PORTD5 54 | #define PD6 PORTD6 55 | #define PD7 PORTD7 56 | #endif 57 | #ifndef PH0 58 | #define PH0 PORTH0 59 | #define PH1 PORTH1 60 | #define PH2 PORTH2 61 | #define PH3 PORTH3 62 | #define PH4 PORTH4 63 | #define PH5 PORTH5 64 | #define PH6 PORTH6 65 | #define PH7 PORTH7 66 | #endif 67 | 68 | /* Chip Specific Pinouts */ 69 | #if defined (__AVR_ATmega168__) \ 70 | || defined (__AVR_ATmega168P__) \ 71 | || defined (__AVR_ATmega88P__) \ 72 | || defined (__AVR_ATmega88__) \ 73 | || defined (__AVR_ATmega48P__) \ 74 | || defined (__AVR_ATmega48__) \ 75 | || defined (__AVR_ATmega328P__) 76 | 77 | /* Diecimila / Duemilanove / almost everything */ 78 | #include "ATmega_xx8.h" 79 | 80 | #elif defined (__AVR_ATmega8__) 81 | 82 | /* ATmega8 */ 83 | #include "ATmega_8.h" 84 | 85 | #elif defined (__AVR_ATmega164P__) \ 86 | || defined (__AVR_ATmega324P__) \ 87 | || defined (__AVR_ATmega644__) \ 88 | || defined (__AVR_ATmega644P__) 89 | 90 | /* Sanguino */ 91 | #include "ATmega_xx4.h" 92 | 93 | #elif defined (__AVR_ATmega640__) \ 94 | || defined (__AVR_ATmega1280__) \ 95 | || defined (__AVR_ATmega1281__) \ 96 | || defined (__AVR_ATmega2560__) \ 97 | || defined (__AVR_ATmega2561__) 98 | 99 | /* Arduino Mega */ 100 | #include "Arduino_Mega.h" 101 | 102 | #elif defined (__AVR_ATmega32U4__) 103 | 104 | /* Teensy 2.0 */ 105 | #include "Teensy_xxU4.h" 106 | 107 | #elif defined (__AVR_AT90USB646__) \ 108 | || defined (__AVR_AT90USB1286__) 109 | 110 | /* Teensy++ 2.0 */ 111 | #include "Teensypp_xxx6.h" 112 | 113 | #else 114 | #error "Unknown Chip!" 115 | #endif 116 | 117 | #endif 118 | 119 | -------------------------------------------------------------------------------- /src/AlaLedRgb.h: -------------------------------------------------------------------------------- 1 | #ifndef AlaLedRgb_h 2 | #define AlaLedRgb_h 3 | 4 | #include "Ala.h" 5 | 6 | #include "ExtNeoPixel.h" 7 | 8 | /** 9 | * AlaLedRgb can be used to drive a single or multiple RGB leds to perform animations. 10 | * Available drivers are PWM pin, TLC5940, WS2811. 11 | */ 12 | class AlaLedRgb 13 | { 14 | 15 | public: 16 | 17 | AlaLedRgb(); 18 | 19 | void initPWM(byte pinsRed, byte pinGreen, byte pinBlue); 20 | void initPWM(int numLeds, byte *pins); 21 | void initTLC5940(int numLeds, byte *pins); 22 | 23 | /** 24 | * Initializes WS2812 LEDs. It be invoked in the setup() function of the main Arduino sketch. 25 | * 26 | * The type field can be used to set the RGB order and chipset frequency. Constants are ExtNeoPixel.h file. 27 | * It is set by default to NEO_GRB + NEO_KHZ800. 28 | */ 29 | void initWS2812(int numLeds, byte pin, byte type=NEO_GRB+NEO_KHZ800); 30 | 31 | /** 32 | * Sets the maximum brightness level. 33 | */ 34 | void setBrightness(AlaColor maxOut); 35 | 36 | /** 37 | * Sets the maximum refresh rate in Hz (default value is 50 Hz). 38 | * May be useful to reduce flickering in some cases. 39 | */ 40 | void setRefreshRate(int refreshRate); 41 | 42 | int getCurrentRefreshRate(); 43 | 44 | 45 | void setAnimation(int animation, long speed, AlaColor color, bool isSeq=false); 46 | void setAnimation(int animation, long speed, AlaPalette palette, bool isSeq=false); 47 | void setAnimation(AlaSeq animSeq[]); 48 | void setSpeed(long speed); 49 | void setColor(AlaColor color); 50 | int getAnimation(); 51 | 52 | bool runAnimation(); 53 | 54 | 55 | 56 | private: 57 | 58 | void setAnimationFunc(int animation); 59 | void on(); 60 | void off(); 61 | void blink(); 62 | void blinkAlt(); 63 | void sparkle(); 64 | void sparkle2(); 65 | void strobo(); 66 | void cycleColors(); 67 | 68 | void pixelShiftRight(); 69 | void pixelShiftLeft(); 70 | void pixelBounce(); 71 | void pixelSmoothShiftRight(); 72 | void pixelSmoothShiftLeft(); 73 | void comet(); 74 | void cometCol(); 75 | void pixelSmoothBounce(); 76 | void larsonScanner(); 77 | void larsonScanner2(); 78 | 79 | void fadeIn(); 80 | void fadeOut(); 81 | void fadeInOut(); 82 | void glow(); 83 | void plasma(); 84 | void fadeColors(); 85 | void pixelsFadeColors(); 86 | void fadeColorsLoop(); 87 | 88 | void movingBars(); 89 | void movingGradient(); 90 | 91 | void fire(); 92 | void bouncingBalls(); 93 | void bubbles(); 94 | 95 | 96 | byte driver; // type of led driver: ALA_PWM, ALA_TLC5940 97 | byte *pins; // pins where the leds are attached to 98 | AlaColor *leds; // array to store leds brightness values 99 | int numLeds; // number of leds 100 | 101 | int animation; 102 | long speed; 103 | AlaPalette palette; 104 | AlaSeq *animSeq; 105 | int animSeqLen; 106 | long animSeqDuration; 107 | 108 | void (AlaLedRgb::*animFunc)(); 109 | AlaColor maxOut; 110 | int refreshMillis; 111 | int refreshRate; // current refresh rate 112 | unsigned long animStartTime; 113 | unsigned long animSeqStartTime; 114 | unsigned long lastRefreshTime; 115 | 116 | float *pxPos; 117 | float *pxSpeed; 118 | 119 | Adafruit_NeoPixel *neopixels; 120 | 121 | }; 122 | 123 | 124 | #endif -------------------------------------------------------------------------------- /src/Ala.cpp: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | This file is part of the Arduino ALA library. 3 | 4 | The Arduino ALA library is free software: you can redistribute it 5 | and/or modify it under the terms of the GNU General Public License as 6 | published by the Free Software Foundation, either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | The Arduino ALA library is distributed in the hope that it will be 10 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with The Arduino ALA library. If not, see 16 | . 17 | --------------------------------------------------------------------*/ 18 | 19 | #include "Ala.h" 20 | 21 | 22 | AlaColor alaPalNull_[] = { }; 23 | AlaPalette alaPalNull = { 0, alaPalNull_ }; 24 | 25 | // Red,Green,Blue sequence 26 | AlaColor alaPalRgb_[] = { 0xFF0000, 0x00FF00, 0x0000FF }; 27 | AlaPalette alaPalRgb = { 3, alaPalRgb_ }; 28 | 29 | // Rainbow colors 30 | AlaColor alaPalRainbow_[] = 31 | { 32 | 0xFF0000, 0xAB5500, 0xABAB00, 0x00FF00, 33 | 0x00AB55, 0x0000FF, 0x5500AB, 0xAB0055 34 | }; 35 | AlaPalette alaPalRainbow = { 8, alaPalRainbow_ }; 36 | 37 | // Rainbow colors with alternating stripes of black 38 | AlaColor alaPalRainbowStripe_[] = 39 | { 40 | 0xFF0000, 0x000000, 0xAB5500, 0x000000, 0xABAB00, 0x000000, 0x00FF00, 0x000000, 41 | 0x00AB55, 0x000000, 0x0000FF, 0x000000, 0x5500AB, 0x000000, 0xAB0055, 0x000000 42 | }; 43 | AlaPalette alaPalRainbowStripe = { 16, alaPalRainbowStripe_ }; 44 | 45 | 46 | // Blue purple ping red orange yellow (and back) 47 | // Basically, everything but the greens. 48 | // This palette is good for lighting at a club or party. 49 | AlaColor alaPalParty_[] = 50 | { 51 | 0x5500AB, 0x84007C, 0xB5004B, 0xE5001B, 52 | 0xE81700, 0xB84700, 0xAB7700, 0xABAB00, 53 | 0xAB5500, 0xDD2200, 0xF2000E, 0xC2003E, 54 | 0x8F0071, 0x5F00A1, 0x2F00D0, 0x0007F9 55 | }; 56 | AlaPalette alaPalParty = { 16, alaPalParty_ }; 57 | 58 | 59 | // Approximate "black body radiation" palette, akin to 60 | // the FastLED 'HeatColor' function. 61 | // Recommend that you use values 0-240 rather than 62 | // the usual 0-255, as the last 15 colors will be 63 | // 'wrapping around' from the hot end to the cold end, 64 | // which looks wrong. 65 | AlaColor alaPalHeat_[] = 66 | { 67 | 0x000000, 0xFF0000, 0xFFFF00, 0xFFFFCC 68 | }; 69 | AlaPalette alaPalHeat = { 4, alaPalHeat_ }; 70 | 71 | 72 | AlaColor alaPalFire_[] = 73 | { 74 | 0x000000, 0x220000, 75 | 0x880000, 0xFF0000, 76 | 0xFF6600, 0xFFCC00 77 | }; 78 | AlaPalette alaPalFire = { 6, alaPalFire_ }; 79 | 80 | AlaColor alaPalCool_[] = 81 | { 82 | 0x0000FF, 83 | 0x0099DD, 0x444488, 0x9900DD 84 | }; 85 | AlaPalette alaPalCool = { 4, alaPalCool_ }; 86 | 87 | 88 | 89 | 90 | 91 | int getStep(long t0, long t, int v) 92 | { 93 | return ((millis()-t0)%t)*v/t; 94 | } 95 | 96 | float getStepFloat(long t0, long t, float v) 97 | { 98 | return ((millis()-t0)%t)*v/t; 99 | } 100 | 101 | float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) 102 | { 103 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 104 | } 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /examples/RgbStripSerial/RgbStripSerial.ino: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ALA library example: RgbStripSerial 4 | // 5 | // Example to demonstrate how to control WS2812 RGB LED strip lighting and animations 6 | // sending AT commands through the serial port. 7 | // 8 | // Web page: http://yaab-arduino.blogspot.com/p/ala-example-rgbstripserial.html 9 | // 10 | /////////////////////////////////////////////////////////////////////////////////////////// 11 | 12 | #include 13 | #include 14 | 15 | #define WS2811_PIN 6 // WS2811 control connected to pin 6 16 | #define NUM_PIXELS 10 // number of leds in the LED strip 17 | #define CMDBUFSIZE 16 // buffer size for receiving serial commands 18 | 19 | AlaLedRgb rgbStrip; 20 | char cmdBuffer[CMDBUFSIZE]; 21 | 22 | // global settings and initial values 23 | int animation = ALA_OFF; 24 | AlaColor color = 0xdddddd; 25 | AlaColor white = 0xffffff; 26 | AlaPalette palette = alaPalNull; 27 | int paletteId=0; 28 | float brightness = 0.3; 29 | long duration = 5000; 30 | 31 | 32 | void setup() 33 | { 34 | rgbStrip.initWS2812(NUM_PIXELS, WS2811_PIN); 35 | rgbStrip.setBrightness(color.scale(brightness)); 36 | rgbStrip.setAnimation(animation, duration, color); 37 | 38 | Serial.begin(9600); 39 | 40 | Serial.println("Welcome to ALA RgbStripSerial example"); 41 | Serial.println("A=[animation code] Set the animation. See https://github.com/bportaluri/ALA/blob/master/src/AlaLed.h"); 42 | Serial.println("B=[brightness] Set the brightness [0-100]"); 43 | Serial.println("D=[duration] Set the duration in milliseconds of the animation cycle"); 44 | Serial.println("C=[color] Set the color (hexadecimal RGB representation ex. 0xE8A240)"); 45 | Serial.println("P=[palette] Set the palette."); 46 | } 47 | 48 | void loop() 49 | { 50 | 51 | if (Serial.available()) 52 | { 53 | int charsRead; 54 | charsRead = Serial.readBytesUntil('\n', cmdBuffer, sizeof(cmdBuffer) - 1); //read entire line 55 | cmdBuffer[charsRead] = '\0'; // Make it a C string 56 | Serial.print(">"); Serial.println(cmdBuffer); 57 | 58 | if(cmdBuffer[1] != '=' || strlen(cmdBuffer)<3) 59 | { 60 | Serial.println("KO"); 61 | } 62 | else 63 | { 64 | switch(toupper(cmdBuffer[0])) 65 | { 66 | case 'A': 67 | animation = atoi(&cmdBuffer[2]); 68 | Serial.println("OK"); 69 | break; 70 | case 'B': 71 | brightness = atoi(&cmdBuffer[2]); 72 | rgbStrip.setBrightness(white.scale((float)brightness / 100)); 73 | Serial.println("OK"); 74 | break; 75 | case 'C': 76 | color = strtol(&cmdBuffer[2], 0, 16); 77 | palette=alaPalNull; 78 | Serial.println("OK"); 79 | break; 80 | case 'D': 81 | duration = atol(&cmdBuffer[2]); 82 | Serial.println("OK"); 83 | break; 84 | case 'P': 85 | paletteId = atoi(&cmdBuffer[2]); 86 | switch(paletteId) 87 | { 88 | case 0: 89 | palette=alaPalNull; 90 | break; 91 | case 1: 92 | palette=alaPalRgb; 93 | break; 94 | case 2: 95 | palette=alaPalRainbow; 96 | break; 97 | case 3: 98 | palette=alaPalParty; 99 | break; 100 | case 4: 101 | palette=alaPalHeat; 102 | break; 103 | case 5: 104 | palette=alaPalFire; 105 | break; 106 | case 6: 107 | palette=alaPalCool; 108 | break; 109 | } 110 | break; 111 | 112 | default: 113 | Serial.println("KO"); 114 | } 115 | 116 | if(palette==alaPalNull) 117 | rgbStrip.setAnimation(animation, duration, color); 118 | else 119 | rgbStrip.setAnimation(animation, duration, palette); 120 | } 121 | } 122 | 123 | rgbStrip.runAnimation(); 124 | } 125 | 126 | 127 | -------------------------------------------------------------------------------- /src/ExtTlc5940Config.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 by Alex Leone 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | #ifndef TLC_CONFIG_H 20 | #define TLC_CONFIG_H 21 | 22 | #include 23 | 24 | /** \file 25 | Configuration for the Arduino Tlc5940 library. After making changes to 26 | this file, delete Tlc5940.o in this folder so the changes are applied. 27 | 28 | A summary of all the options: 29 | - Number of TLCs daisy-chained: NUM_TLCS (default 1) 30 | - Enable/Disable VPRG functionality: VPRG_ENABLED (default 0) 31 | - Enable/Disable XERR functionality: XERR_ENABLED (default 0) 32 | - Should the library use bit-banging (any pins) or hardware SPI (faster): 33 | DATA_TRANSFER_MODE (default TLC_SPI) 34 | - Which pins to use for bit-banging: SIN_PIN, SIN_PORT, SIN_DDR and 35 | SCLK_PIN, SCLK_PORT, SCLK_DDR 36 | - The PWM period: TLC_PWM_PERIOD (be sure to change TLC_GSCLK_PERIOD 37 | accordingly!) 38 | 39 | How to change the pin mapping: 40 | - Arduino digital pin 0-7 = PORTD, PD0-7 41 | - Arduino digital pin 8-13 = PORTB, PB0-5 42 | - Arduino analog pin 0-5 = PORTC, PC0-5 */ 43 | 44 | /** Bit-bang using any two i/o pins */ 45 | #define TLC_BITBANG 1 46 | /** Use the much faster hardware SPI module */ 47 | #define TLC_SPI 2 48 | 49 | /* ------------------------ START EDITING HERE ----------------------------- */ 50 | 51 | /** Number of TLCs daisy-chained. To daisy-chain, attach the SOUT (TLC pin 17) 52 | of the first TLC to the SIN (TLC pin 26) of the next. The rest of the pins 53 | are attached normally. 54 | \note Each TLC needs it's own IREF resistor */ 55 | #define NUM_TLCS 1 56 | 57 | /** Determines how data should be transfered to the TLCs. Bit-banging can use 58 | any two i/o pins, but the hardware SPI is faster. 59 | - Bit-Bang = TLC_BITBANG 60 | - Hardware SPI = TLC_SPI (default) */ 61 | #define DATA_TRANSFER_MODE TLC_SPI 62 | 63 | /* This include is down here because the files it includes needs the data 64 | transfer mode */ 65 | #include "pinouts/chip_includes.h" 66 | 67 | /* Set DATA_TRANSFER_MODE to TLC_BITBANG and change the pins below if you need 68 | to use different pins for sin and sclk. The defaults are defined in 69 | pinouts/ATmega_xx8.h for most Arduino's. */ 70 | 71 | #if DATA_TRANSFER_MODE == TLC_BITBANG 72 | /** SIN (TLC pin 26) */ 73 | #define SIN_PIN DEFAULT_BB_SIN_PIN 74 | #define SIN_PORT DEFAULT_BB_SIN_PORT 75 | #define SIN_DDR DEFAULT_BB_SIN_DDR 76 | /** SCLK (TLC pin 25) */ 77 | #define SCLK_PIN DEFAULT_BB_SCLK_PIN 78 | #define SCLK_PORT DEFAULT_BB_SCLK_PORT 79 | #define SCLK_DDR DEFAULT_BB_SCLK_DDR 80 | #endif 81 | 82 | 83 | /** If more than 16 TLCs are daisy-chained, the channel type has to be uint16_t. 84 | Default is uint8_t, which supports up to 16 TLCs. */ 85 | #define TLC_CHANNEL_TYPE uint8_t 86 | 87 | /** Determines how long each PWM period should be, in clocks. 88 | \f$\displaystyle f_{PWM} = \frac{f_{osc}}{2 * TLC\_PWM\_PERIOD} Hz \f$ 89 | \f$\displaystyle TLC\_PWM\_PERIOD = \frac{f_{osc}}{2 * f_{PWM}} \f$ 90 | This is related to TLC_GSCLK_PERIOD: 91 | \f$\displaystyle TLC\_PWM\_PERIOD = 92 | \frac{(TLC\_GSCLK\_PERIOD + 1) * 4096}{2} \f$ 93 | \note The default of 8192 means the PWM frequency is 976.5625Hz */ 94 | #define TLC_PWM_PERIOD 8192 95 | 96 | /** Determines how long each period GSCLK is. 97 | This is related to TLC_PWM_PERIOD: 98 | \f$\displaystyle TLC\_GSCLK\_PERIOD = 99 | \frac{2 * TLC\_PWM\_PERIOD}{4096} - 1 \f$ 100 | \note Default is 3 */ 101 | #define TLC_GSCLK_PERIOD 3 102 | 103 | /** Enables/disables VPRG (TLC pin 27) functionality. If you need to set dot 104 | correction data, this needs to be enabled. 105 | - 0 VPRG is not connected. TLC pin 27 must be grounded! (default) 106 | - 1 VPRG is connected 107 | \note VPRG to GND inputs grayscale data, VPRG to Vcc inputs dot-correction 108 | data */ 109 | #define VPRG_ENABLED 0 110 | 111 | /** Enables/disables XERR (TLC pin 16) functionality to check for shorted/broken 112 | LEDs 113 | - 0 XERR is not connected (default) 114 | - 1 XERR is connected 115 | \note XERR is active low */ 116 | #define XERR_ENABLED 0 117 | 118 | /* You can change the VPRG and XERR pins freely. The defaults are defined in 119 | the chip-specific pinouts: see pinouts/ATmega_xx8.h for most Arduino's. */ 120 | 121 | #if VPRG_ENABLED 122 | /** VPRG (TLC pin 27) */ 123 | #define VPRG_PIN DEFAULT_VPRG_PIN 124 | #define VPRG_PORT DEFAULT_VPRG_PORT 125 | #define VPRG_DDR DEFAULT_VPRG_DDR 126 | #endif 127 | 128 | #if XERR_ENABLED 129 | /** XERR (TLC pin 16) */ 130 | #define XERR_PIN DEFAULT_XERR_PIN 131 | #define XERR_PORT DEFAULT_XERR_PORT 132 | #define XERR_DDR DEFAULT_XERR_DDR 133 | #define XERR_PINS DEFAULT_XERR_PINS 134 | #endif 135 | 136 | /* ------------------------- STOP EDITING HERE ----------------------------- */ 137 | 138 | #if DATA_TRANSFER_MODE == TLC_SPI 139 | /** SIN (TLC pin 26) */ 140 | #define SIN_PIN TLC_MOSI_PIN 141 | #define SIN_PORT TLC_MOSI_PORT 142 | #define SIN_DDR TLC_MOSI_DDR 143 | /** SCLK (TLC pin 25) */ 144 | #define SCLK_PIN TLC_SCK_PIN 145 | #define SCLK_PORT TLC_SCK_PORT 146 | #define SCLK_DDR TLC_SCK_DDR 147 | #endif 148 | 149 | 150 | 151 | #if !(DATA_TRANSFER_MODE == TLC_BITBANG \ 152 | || DATA_TRANSFER_MODE == TLC_SPI) 153 | #error "Invalid DATA_TRANSFER_MODE specified, see DATA_TRANSFER_MODE" 154 | #endif 155 | 156 | /* Various Macros */ 157 | 158 | /** Arranges 2 grayscale values (0 - 4095) in the packed array format (3 bytes). 159 | This is for array initializers only: the output is three comma seperated 160 | 8-bit values. */ 161 | #define GS_DUO(a, b) ((a) >> 4), ((a) << 4) | ((b) >> 8), (b) 162 | 163 | 164 | #if VPRG_ENABLED 165 | /** Arranges 4 dot correction values (0 - 63) in the packed array format. 166 | \see setDCtoProgmemArray */ 167 | #define DC_QUARTET(a, b, c, d) ((a) << 2) | ((b) >> 4), \ 168 | ((b) << 4) | ((c) >> 2), \ 169 | ((c) << 6) | (d) 170 | #endif 171 | 172 | #endif 173 | 174 | -------------------------------------------------------------------------------- /src/Ala.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | This file is part of the Arduino ALA library. 3 | 4 | The Arduino ALA library is free software: you can redistribute it 5 | and/or modify it under the terms of the GNU General Public License as 6 | published by the Free Software Foundation, either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | The Arduino ALA library is distributed in the hope that it will be 10 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with The Arduino ALA library. If not, see 16 | . 17 | --------------------------------------------------------------------*/ 18 | 19 | #ifndef Ala_h 20 | #define Ala_h 21 | 22 | #include 23 | #include "Arduino.h" 24 | 25 | 26 | //////////////////////////////////////////////////////////////////////////////// 27 | // Drivers 28 | 29 | #define ALA_PWM 1 30 | #define ALA_TLC5940 2 31 | #define ALA_WS2812 3 32 | 33 | 34 | //////////////////////////////////////////////////////////////////////////////// 35 | // Animations 36 | 37 | #define ALA_ON 101 38 | #define ALA_OFF 102 39 | #define ALA_BLINK 103 40 | #define ALA_BLINKALT 104 41 | #define ALA_SPARKLE 105 42 | #define ALA_SPARKLE2 106 43 | #define ALA_STROBO 107 44 | 45 | #define ALA_CYCLECOLORS 151 46 | 47 | #define ALA_PIXELSHIFTRIGHT 201 48 | #define ALA_PIXELSHIFTLEFT 202 49 | #define ALA_PIXELBOUNCE 203 50 | #define ALA_PIXELSMOOTHSHIFTRIGHT 211 51 | #define ALA_PIXELSMOOTHSHIFTLEFT 212 52 | #define ALA_PIXELSMOOTHBOUNCE 213 53 | #define ALA_COMET 221 54 | #define ALA_COMETCOL 222 55 | #define ALA_BARSHIFTRIGHT 231 56 | #define ALA_BARSHIFTLEFT 232 57 | #define ALA_MOVINGBARS 241 58 | #define ALA_MOVINGGRADIENT 242 59 | #define ALA_LARSONSCANNER 251 60 | #define ALA_LARSONSCANNER2 252 61 | 62 | #define ALA_FADEIN 301 63 | #define ALA_FADEOUT 302 64 | #define ALA_FADEINOUT 303 65 | #define ALA_GLOW 304 66 | #define ALA_PLASMA 305 67 | 68 | #define ALA_FADECOLORS 351 69 | #define ALA_FADECOLORSLOOP 352 70 | #define ALA_PIXELSFADECOLORS 353 71 | #define ALA_FLAME 354 72 | 73 | #define ALA_FIRE 501 74 | #define ALA_BOUNCINGBALLS 502 75 | #define ALA_BUBBLES 503 76 | 77 | #define ALA_ENDSEQ 0 78 | #define ALA_STOPSEQ 1 79 | 80 | //////////////////////////////////////////////////////////////////////////////// 81 | 82 | // Strobo effect duty cycle (10=1/10) 83 | #define ALA_STROBODC 10 84 | 85 | 86 | //////////////////////////////////////////////////////////////////////////////// 87 | 88 | struct AlaColor 89 | { 90 | union 91 | { 92 | struct 93 | { 94 | uint8_t r; 95 | uint8_t g; 96 | uint8_t b; 97 | }; 98 | uint8_t raw[3]; 99 | }; 100 | 101 | inline AlaColor() __attribute__((always_inline)) 102 | { 103 | } 104 | 105 | // allow construction from R, G, B 106 | inline AlaColor( uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline)) 107 | : r(ir), g(ig), b(ib) 108 | { 109 | } 110 | 111 | // allow construction from 32-bit (really 24-bit) bit 0xRRGGBB color code 112 | inline AlaColor( uint32_t colorcode) __attribute__((always_inline)) 113 | : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF) 114 | { 115 | } 116 | 117 | bool operator == (const AlaColor &c) const 118 | { 119 | return(this->r == c.r and this->g == c.g and this->b == c.b); 120 | } 121 | /* 122 | AlaColor getPixel(AlaColor maxOut) 123 | { 124 | return AlaColor(r*maxOut.r/255, g*maxOut.g/255, b*maxOut.b/255); 125 | } 126 | */ 127 | AlaColor sum(AlaColor color) 128 | { 129 | int r0 = min(color.r + r, 255); 130 | int g0 = min(color.g + g, 255); 131 | int b0 = min(color.b + b, 255); 132 | return AlaColor(r0, g0, b0); 133 | } 134 | 135 | AlaColor interpolate(AlaColor color, float x) 136 | { 137 | int r0 = x*(color.r - r) + r; 138 | int g0 = x*(color.g - g) + g; 139 | int b0 = x*(color.b - b) + b; 140 | return AlaColor(r0, g0, b0); 141 | } 142 | 143 | AlaColor scale(float k) 144 | { 145 | int r0 = min(r*k, 255); 146 | int g0 = min(g*k, 255); 147 | int b0 = min(b*k, 255); 148 | return AlaColor(r0, g0, b0); 149 | } 150 | 151 | 152 | typedef enum { 153 | Aqua = 0x00FFFF, 154 | Black = 0x000000, 155 | Blue = 0x0000FF, 156 | Cyan = 0x00FFFF, 157 | Gold = 0xFFD700, 158 | Gray = 0x808080, 159 | Green = 0x008000, 160 | Lime = 0x00FF00, 161 | Magenta = 0xFF00FF, 162 | Navy = 0x000080, 163 | Olive = 0x808000, 164 | Purple = 0x800080, 165 | Red = 0xFF0000, 166 | Teal = 0x008080, 167 | White = 0xFFFFFF, 168 | Yellow = 0xFFFF00 169 | } ColorCodes; 170 | } ; 171 | 172 | 173 | 174 | //////////////////////////////////////////////////////////////////////////////// 175 | // Struct definitions 176 | //////////////////////////////////////////////////////////////////////////////// 177 | 178 | struct AlaPalette 179 | { 180 | int numColors; 181 | AlaColor *colors; 182 | 183 | /** 184 | * Get the interpolated color from the palette. 185 | * The argument is a floating number between 0 and numColors. 186 | */ 187 | AlaColor getPalColor(float i) 188 | { 189 | int i0 = (int)i%(numColors); 190 | int i1 = (int)(i+1)%(numColors); 191 | 192 | // decimal part is used to interpolate between the two colors 193 | float t0 = i - trunc(i); 194 | //float t0 = i - (int)i; 195 | 196 | return colors[i0].interpolate(colors[i1], t0); 197 | } 198 | 199 | bool operator == (const AlaPalette &c) const 200 | { 201 | if (!(this->numColors == c.numColors)) 202 | return false; 203 | 204 | for(int i=0; icolors[i] == c.colors[i])) 207 | return false; 208 | } 209 | return true; 210 | } 211 | 212 | }; 213 | 214 | 215 | struct AlaSeq 216 | { 217 | int animation; 218 | long speed; 219 | long duration; 220 | AlaPalette palette; 221 | }; 222 | 223 | 224 | //////////////////////////////////////////////////////////////////////////////// 225 | // Palette definitions 226 | //////////////////////////////////////////////////////////////////////////////// 227 | 228 | // Empty palette 229 | extern AlaPalette alaPalNull; 230 | 231 | // Red,Green,Blue sequence 232 | extern AlaPalette alaPalRgb; 233 | 234 | // Rainbow colors 235 | extern AlaPalette alaPalRainbow; 236 | 237 | // Rainbow colors with alternating stripes of black 238 | extern AlaPalette alaPalRainbowStripe; 239 | 240 | extern AlaPalette alaPalParty; 241 | 242 | extern AlaPalette alaPalHeat; 243 | 244 | // Fire palette to be used with ALA_FIRE effect 245 | extern AlaPalette alaPalFire; 246 | 247 | extern AlaPalette alaPalCool; 248 | 249 | 250 | 251 | 252 | //////////////////////////////////////////////////////////////////////////////// 253 | // Utility functions 254 | //////////////////////////////////////////////////////////////////////////////// 255 | 256 | int getStep(long t0, long t, int v); 257 | float getStepFloat(long t0, long t, float v); 258 | float mapfloat(float x, float in_min, float in_max, float out_min, float out_max); 259 | 260 | 261 | #endif -------------------------------------------------------------------------------- /src/ExtNeoPixel.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------------------------------- 2 | This file is part of the Adafruit NeoPixel library. 3 | 4 | NeoPixel is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as 6 | published by the Free Software Foundation, either version 3 of 7 | the License, or (at your option) any later version. 8 | 9 | NeoPixel is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with NeoPixel. If not, see 16 | . 17 | --------------------------------------------------------------------*/ 18 | 19 | #ifndef ADAFRUIT_NEOPIXEL_H 20 | #define ADAFRUIT_NEOPIXEL_H 21 | 22 | #if (ARDUINO >= 100) 23 | #include 24 | #else 25 | #include 26 | #include 27 | #endif 28 | 29 | // The order of primary colors in the NeoPixel data stream can vary 30 | // among device types, manufacturers and even different revisions of 31 | // the same item. The third parameter to the Adafruit_NeoPixel 32 | // constructor encodes the per-pixel byte offsets of the red, green 33 | // and blue primaries (plus white, if present) in the data stream -- 34 | // the following #defines provide an easier-to-use named version for 35 | // each permutation. e.g. NEO_GRB indicates a NeoPixel-compatible 36 | // device expecting three bytes per pixel, with the first byte 37 | // containing the green value, second containing red and third 38 | // containing blue. The in-memory representation of a chain of 39 | // NeoPixels is the same as the data-stream order; no re-ordering of 40 | // bytes is required when issuing data to the chain. 41 | 42 | // Bits 5,4 of this value are the offset (0-3) from the first byte of 43 | // a pixel to the location of the red color byte. Bits 3,2 are the 44 | // green offset and 1,0 are the blue offset. If it is an RGBW-type 45 | // device (supporting a white primary in addition to R,G,B), bits 7,6 46 | // are the offset to the white byte...otherwise, bits 7,6 are set to 47 | // the same value as 5,4 (red) to indicate an RGB (not RGBW) device. 48 | // i.e. binary representation: 49 | // 0bWWRRGGBB for RGBW devices 50 | // 0bRRRRGGBB for RGB 51 | 52 | // RGB NeoPixel permutations; white and red offsets are always same 53 | // Offset: W R G B 54 | #define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) 55 | #define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) 56 | #define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) 57 | #define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) 58 | #define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) 59 | #define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) 60 | 61 | // RGBW NeoPixel permutations; all 4 offsets are distinct 62 | // Offset: W R G B 63 | #define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) 64 | #define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) 65 | #define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) 66 | #define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) 67 | #define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) 68 | #define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) 69 | 70 | #define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) 71 | #define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) 72 | #define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) 73 | #define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) 74 | #define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) 75 | #define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) 76 | 77 | #define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) 78 | #define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) 79 | #define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) 80 | #define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) 81 | #define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) 82 | #define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) 83 | 84 | #define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) 85 | #define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) 86 | #define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) 87 | #define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) 88 | #define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) 89 | #define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) 90 | 91 | // Add NEO_KHZ400 to the color order value to indicate a 400 KHz 92 | // device. All but the earliest v1 NeoPixels expect an 800 KHz data 93 | // stream, this is the default if unspecified. Because flash space 94 | // is very limited on ATtiny devices (e.g. Trinket, Gemma), v1 95 | // NeoPixels aren't handled by default on those chips, though it can 96 | // be enabled by removing the ifndef/endif below -- but code will be 97 | // bigger. Conversely, can disable the NEO_KHZ400 line on other MCUs 98 | // to remove v1 support and save a little space. 99 | 100 | #define NEO_KHZ800 0x0000 // 800 KHz datastream 101 | #ifndef __AVR_ATtiny85__ 102 | #define NEO_KHZ400 0x0100 // 400 KHz datastream 103 | #endif 104 | 105 | // If 400 KHz support is enabled, the third parameter to the constructor 106 | // requires a 16-bit value (in order to select 400 vs 800 KHz speed). 107 | // If only 800 KHz is enabled (as is default on ATtiny), an 8-bit value 108 | // is sufficient to encode pixel color order, saving some space. 109 | 110 | #ifdef NEO_KHZ400 111 | typedef uint16_t neoPixelType; 112 | #else 113 | typedef uint8_t neoPixelType; 114 | #endif 115 | 116 | class Adafruit_NeoPixel { 117 | 118 | public: 119 | 120 | // Constructor: number of LEDs, pin number, LED type 121 | Adafruit_NeoPixel(uint16_t n, uint8_t p=6, neoPixelType t=NEO_GRB + NEO_KHZ800); 122 | Adafruit_NeoPixel(void); 123 | ~Adafruit_NeoPixel(); 124 | 125 | void 126 | begin(void), 127 | show(void), 128 | setPin(uint8_t p), 129 | setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b), 130 | setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w), 131 | setPixelColor(uint16_t n, uint32_t c), 132 | setBrightness(uint8_t), 133 | clear(), 134 | updateLength(uint16_t n), 135 | updateType(neoPixelType t); 136 | uint8_t 137 | *getPixels(void) const, 138 | getBrightness(void) const, 139 | sine8(uint8_t) const, 140 | gamma8(uint8_t) const; 141 | int8_t 142 | getPin(void) { return pin; }; 143 | uint16_t 144 | numPixels(void) const; 145 | static uint32_t 146 | Color(uint8_t r, uint8_t g, uint8_t b), 147 | Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w); 148 | uint32_t 149 | getPixelColor(uint16_t n) const; 150 | inline bool 151 | canShow(void) { return (micros() - endTime) >= 300L; } 152 | 153 | protected: 154 | 155 | boolean 156 | #ifdef NEO_KHZ400 // If 400 KHz NeoPixel support enabled... 157 | is800KHz, // ...true if 800 KHz pixels 158 | #endif 159 | begun; // true if begin() previously called 160 | uint16_t 161 | numLEDs, // Number of RGB LEDs in strip 162 | numBytes; // Size of 'pixels' buffer below (3 or 4 bytes/pixel) 163 | int8_t 164 | pin; // Output pin number (-1 if not yet set) 165 | uint8_t 166 | brightness, 167 | *pixels, // Holds LED color values (3 or 4 bytes each) 168 | rOffset, // Index of red byte within each 3- or 4-byte pixel 169 | gOffset, // Index of green byte 170 | bOffset, // Index of blue byte 171 | wOffset; // Index of white byte (same as rOffset if no white) 172 | uint32_t 173 | endTime; // Latch timing reference 174 | #ifdef __AVR__ 175 | volatile uint8_t 176 | *port; // Output PORT register 177 | uint8_t 178 | pinMask; // Output PORT bitmask 179 | #endif 180 | }; 181 | 182 | #endif // ADAFRUIT_NEOPIXEL_H 183 | -------------------------------------------------------------------------------- /src/AlaLed.cpp: -------------------------------------------------------------------------------- 1 | #include "AlaLed.h" 2 | 3 | #include "ExtTlc5940.h" 4 | 5 | 6 | AlaLed::AlaLed() 7 | { 8 | maxOut = 255; 9 | speed = 1000; 10 | animSeqLen = 0; 11 | lastRefreshTime = 0; 12 | refreshMillis = 1000/50; 13 | } 14 | 15 | 16 | 17 | void AlaLed::initPWM(byte pin) 18 | { 19 | byte *pins_ = (byte *)malloc(1); 20 | pins_[0] = pin; 21 | 22 | initPWM(1, pins_); 23 | } 24 | 25 | 26 | void AlaLed::initPWM(int numLeds, byte *pins) 27 | { 28 | this->driver = ALA_PWM; 29 | this->numLeds = numLeds; 30 | this->pins = pins; 31 | 32 | for (int x=0; xdriver = ALA_TLC5940; 45 | this->numLeds = numLeds; 46 | this->pins = pins; 47 | 48 | // allocate and clear leds array 49 | leds = (byte *)malloc(numLeds); 50 | memset(leds, 0, numLeds); 51 | 52 | // call Tlc.init only once 53 | static bool isTlcInit = false; 54 | if(!isTlcInit) 55 | { 56 | Tlc.init(0); 57 | isTlcInit=true; 58 | } 59 | } 60 | 61 | 62 | 63 | void AlaLed::setBrightness(byte maxOut) 64 | { 65 | this->maxOut = maxOut; 66 | } 67 | 68 | void AlaLed::setRefreshRate(int refreshRate) 69 | { 70 | this->refreshMillis = 1000/refreshRate; 71 | } 72 | 73 | 74 | void AlaLed::setAnimation(int animation, long speed, bool isSeq) 75 | { 76 | if (this->animation == animation && this->speed == speed) 77 | return; 78 | 79 | this->animation = animation; 80 | this->speed = speed; 81 | 82 | if (!isSeq) 83 | animSeqLen=0; 84 | setAnimationFunc(animation); 85 | animStartTime = millis(); 86 | } 87 | 88 | 89 | void AlaLed::setAnimation(AlaSeq animSeq[]) 90 | { 91 | this->animSeq = animSeq; 92 | 93 | // initialize animSeqDuration and animSeqLen variables 94 | animSeqDuration = 0; 95 | for(animSeqLen=0; animSeq[animSeqLen].animation!=ALA_ENDSEQ; animSeqLen++) 96 | { 97 | animSeqDuration = animSeqDuration + animSeq[animSeqLen].duration; 98 | } 99 | animSeqStartTime = millis(); 100 | setAnimation(animSeq[0].animation, animSeq[0].speed, true); 101 | } 102 | 103 | void AlaLed::setSpeed(long speed) 104 | { 105 | this->speed = speed; 106 | animStartTime = millis(); 107 | } 108 | 109 | 110 | int AlaLed::getAnimation() 111 | { 112 | return animation; 113 | } 114 | 115 | 116 | bool AlaLed::runAnimation() 117 | { 118 | if(animation == ALA_STOPSEQ) 119 | return true; 120 | 121 | // skip the refresh if not enough time has passed since last update 122 | unsigned long cTime = millis(); 123 | if (cTime < lastRefreshTime + refreshMillis) 124 | return false; 125 | 126 | // calculate real refresh rate 127 | refreshRate = 1000/(cTime - lastRefreshTime); 128 | 129 | lastRefreshTime = cTime; 130 | 131 | // if it's a sequence we have to calculate the current animation 132 | if (animSeqLen != 0) 133 | { 134 | long c = 0; 135 | long t = (cTime-animSeqStartTime) % animSeqDuration; 136 | for(int i=0; i=c && t<(c+animSeq[i].duration)) 139 | { 140 | setAnimation(animSeq[i].animation, animSeq[i].speed, true); 141 | break; 142 | } 143 | c = c + animSeq[i].duration; 144 | } 145 | } 146 | 147 | 148 | // run the animantion calculation 149 | if (animFunc != NULL) 150 | (this->*animFunc)(); 151 | 152 | // update leds 153 | if(driver==ALA_PWM) 154 | { 155 | for(int i=0; is-l) 368 | leds[x] = maxOut; 369 | else 370 | leds[x] = 0; 371 | } 372 | } 373 | 374 | void AlaLed::barShiftLeft() 375 | { 376 | int l = numLeds/2+1; // length of the bar 377 | 378 | int s = map(getStep(animStartTime, speed, 1000), 0, 1000, 0, numLeds+l); 379 | 380 | for(int x=0; xs-l) 383 | leds[numLeds-x-1] = maxOut; 384 | else 385 | leds[numLeds-x-1] = 0; 386 | } 387 | } 388 | 389 | void AlaLed::pixelSmoothBounce() 390 | { 391 | // see larsonScanner 392 | float t = getStepFloat(animStartTime, speed, 2*numLeds-2); 393 | 394 | for(int x=0; x7, 3-11, 4-14 415 | float t = getStepFloat(animStartTime, speed, 2*numLeds+(l*4-1)); 416 | 417 | for(int x=0; x 2 | 3 | This file is part of the Arduino TLC5940 Library. 4 | 5 | The Arduino TLC5940 Library is free software: you can redistribute it 6 | and/or modify it under the terms of the GNU General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | The Arduino TLC5940 Library is distributed in the hope that it will be 11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with The Arduino TLC5940 Library. If not, see 17 | . */ 18 | 19 | /** \file 20 | Tlc5940 class functions. */ 21 | 22 | #include 23 | #include 24 | 25 | #include "ExtTlc5940Config.h" 26 | #include "ExtTlc5940.h" 27 | 28 | /** Pulses a pin - high then low. */ 29 | #define pulse_pin(port, pin) port |= _BV(pin); port &= ~_BV(pin) 30 | 31 | /** This will be true (!= 0) if update was just called and the data has not 32 | been latched in yet. */ 33 | volatile uint8_t tlc_needXLAT; 34 | 35 | /** Some of the extened library will need to be called after a successful 36 | update. */ 37 | volatile void (*tlc_onUpdateFinished)(void); 38 | 39 | /** Packed grayscale data, 24 bytes (16 * 12 bits) per TLC. 40 | 41 | Format: Lets assume we have 2 TLCs, A and B, daisy-chained with the SOUT of 42 | A going into the SIN of B. 43 | - byte 0: upper 8 bits of B.15 44 | - byte 1: lower 4 bits of B.15 and upper 4 bits of B.14 45 | - byte 2: lower 8 bits of B.0 46 | - ... 47 | - byte 24: upper 8 bits of A.15 48 | - byte 25: lower 4 bits of A.15 and upper 4 bits of A.14 49 | - ... 50 | - byte 47: lower 8 bits of A.0 51 | 52 | \note Normally packing data like this is bad practice. But in this 53 | situation, shifting the data out is really fast because the format of 54 | the array is the same as the format of the TLC's serial interface. */ 55 | uint8_t tlc_GSData[NUM_TLCS * 24]; 56 | 57 | /** Don't add an extra SCLK pulse after switching from dot-correction mode. */ 58 | static uint8_t firstGSInput; 59 | 60 | /** Interrupt called after an XLAT pulse to prevent more XLAT pulses. */ 61 | ISR(TIMER1_OVF_vect) 62 | { 63 | disable_XLAT_pulses(); 64 | clear_XLAT_interrupt(); 65 | tlc_needXLAT = 0; 66 | if (tlc_onUpdateFinished) { 67 | sei(); 68 | tlc_onUpdateFinished(); 69 | } 70 | } 71 | 72 | /** \defgroup ReqVPRG_ENABLED Functions that Require VPRG_ENABLED 73 | Functions that require VPRG_ENABLED == 1. 74 | You can enable VPRG by changing 75 | \code #define VPRG_ENABLED 0 \endcode to 76 | \code #define VPRG_ENABLED 1 \endcode in tlc_config.h 77 | 78 | You will also have to connect Arduino digital pin 6 to TLC pin 27. (The 79 | pin to be used can be changed in tlc_config.h). If VPRG is not enabled, 80 | the TLC pin should grounded (remember to unconnect TLC pin 27 from GND 81 | if you do enable VPRG). */ 82 | /* @{ */ /* @} */ 83 | 84 | /** \defgroup CoreFunctions Core Libary Functions 85 | These function are all prefixed with "Tlc." */ 86 | /* @{ */ 87 | 88 | /** Pin i/o and Timer setup. The grayscale register will be reset to all 89 | zeros, or whatever initialValue is set to and the Timers will start. 90 | \param initialValue = 0, optional parameter specifing the inital startup 91 | value */ 92 | void Tlc5940::init(uint16_t initialValue) 93 | { 94 | /* Pin Setup */ 95 | XLAT_DDR |= _BV(XLAT_PIN); 96 | BLANK_DDR |= _BV(BLANK_PIN); 97 | GSCLK_DDR |= _BV(GSCLK_PIN); 98 | #if VPRG_ENABLED 99 | VPRG_DDR |= _BV(VPRG_PIN); 100 | VPRG_PORT &= ~_BV(VPRG_PIN); // grayscale mode (VPRG low) 101 | #endif 102 | #if XERR_ENABLED 103 | XERR_DDR &= ~_BV(XERR_PIN); // XERR as input 104 | XERR_PORT |= _BV(XERR_PIN); // enable pull-up resistor 105 | #endif 106 | BLANK_PORT |= _BV(BLANK_PIN); // leave blank high (until the timers start) 107 | 108 | tlc_shift8_init(); 109 | 110 | setAll(initialValue); 111 | update(); 112 | disable_XLAT_pulses(); 113 | clear_XLAT_interrupt(); 114 | tlc_needXLAT = 0; 115 | pulse_pin(XLAT_PORT, XLAT_PIN); 116 | 117 | 118 | /* Timer Setup */ 119 | 120 | /* Timer 1 - BLANK / XLAT */ 121 | TCCR1A = _BV(COM1B1); // non inverting, output on OC1B, BLANK 122 | TCCR1B = _BV(WGM13); // Phase/freq correct PWM, ICR1 top 123 | OCR1A = 1; // duty factor on OC1A, XLAT is inside BLANK 124 | OCR1B = 2; // duty factor on BLANK (larger than OCR1A (XLAT)) 125 | ICR1 = TLC_PWM_PERIOD; // see tlc_config.h 126 | 127 | /* Timer 2 - GSCLK */ 128 | #if defined(TLC_ATMEGA_8_H) 129 | TCCR2 = _BV(COM20) // set on BOTTOM, clear on OCR2A (non-inverting), 130 | | _BV(WGM21); // output on OC2B, CTC mode with OCR2 top 131 | OCR2 = TLC_GSCLK_PERIOD / 2; // see tlc_config.h 132 | TCCR2 |= _BV(CS20); // no prescale, (start pwm output) 133 | #elif defined(TLC_TIMER3_GSCLK) 134 | TCCR3A = _BV(COM3A1) // set on BOTTOM, clear on OCR3A (non-inverting), 135 | // output on OC3A 136 | | _BV(WGM31); // Fast pwm with ICR3 top 137 | OCR3A = 0; // duty factor (as short a pulse as possible) 138 | ICR3 = TLC_GSCLK_PERIOD; // see tlc_config.h 139 | TCCR3B = _BV(CS30) // no prescale, (start pwm output) 140 | | _BV(WGM32) // Fast pwm with ICR3 top 141 | | _BV(WGM33); // Fast pwm with ICR3 top 142 | #else 143 | TCCR2A = _BV(COM2B1) // set on BOTTOM, clear on OCR2A (non-inverting), 144 | // output on OC2B 145 | | _BV(WGM21) // Fast pwm with OCR2A top 146 | | _BV(WGM20); // Fast pwm with OCR2A top 147 | TCCR2B = _BV(WGM22); // Fast pwm with OCR2A top 148 | OCR2B = 0; // duty factor (as short a pulse as possible) 149 | OCR2A = TLC_GSCLK_PERIOD; // see tlc_config.h 150 | TCCR2B |= _BV(CS20); // no prescale, (start pwm output) 151 | #endif 152 | TCCR1B |= _BV(CS10); // no prescale, (start pwm output) 153 | update(); 154 | } 155 | 156 | /** Clears the grayscale data array, #tlc_GSData, but does not shift in any 157 | data. This call should be followed by update() if you are turning off 158 | all the outputs. */ 159 | void Tlc5940::clear(void) 160 | { 161 | setAll(0); 162 | } 163 | 164 | /** Shifts in the data from the grayscale data array, #tlc_GSData. 165 | If data has already been shifted in this grayscale cycle, another call to 166 | update() will immediately return 1 without shifting in the new data. To 167 | ensure that a call to update() does shift in new data, use 168 | \code while(Tlc.update()); \endcode 169 | or 170 | \code while(tlc_needXLAT); \endcode 171 | \returns 1 if there is data waiting to be latched, 0 if data was 172 | successfully shifted in */ 173 | uint8_t Tlc5940::update(void) 174 | { 175 | if (tlc_needXLAT) { 176 | return 1; 177 | } 178 | disable_XLAT_pulses(); 179 | if (firstGSInput) { 180 | // adds an extra SCLK pulse unless we've just set dot-correction data 181 | firstGSInput = 0; 182 | } else { 183 | pulse_pin(SCLK_PORT, SCLK_PIN); 184 | } 185 | uint8_t *p = tlc_GSData; 186 | while (p < tlc_GSData + NUM_TLCS * 24) { 187 | tlc_shift8(*p++); 188 | tlc_shift8(*p++); 189 | tlc_shift8(*p++); 190 | } 191 | tlc_needXLAT = 1; 192 | enable_XLAT_pulses(); 193 | set_XLAT_interrupt(); 194 | return 0; 195 | } 196 | 197 | /** Sets channel to value in the grayscale data array, #tlc_GSData. 198 | \param channel (0 to #NUM_TLCS * 16 - 1). OUT0 of the first TLC is 199 | channel 0, OUT0 of the next TLC is channel 16, etc. 200 | \param value (0-4095). The grayscale value, 4095 is maximum. 201 | \see get */ 202 | void Tlc5940::set(TLC_CHANNEL_TYPE channel, uint16_t value) 203 | { 204 | TLC_CHANNEL_TYPE index8 = (NUM_TLCS * 16 - 1) - channel; 205 | uint8_t *index12p = tlc_GSData + ((((uint16_t)index8) * 3) >> 1); 206 | if (index8 & 1) { // starts in the middle 207 | // first 4 bits intact | 4 top bits of value 208 | *index12p = (*index12p & 0xF0) | (value >> 8); 209 | // 8 lower bits of value 210 | *(++index12p) = value & 0xFF; 211 | } else { // starts clean 212 | // 8 upper bits of value 213 | *(index12p++) = value >> 4; 214 | // 4 lower bits of value | last 4 bits intact 215 | *index12p = ((uint8_t)(value << 4)) | (*index12p & 0xF); 216 | } 217 | } 218 | 219 | /** Gets the current grayscale value for a channel 220 | \param channel (0 to #NUM_TLCS * 16 - 1). OUT0 of the first TLC is 221 | channel 0, OUT0 of the next TLC is channel 16, etc. 222 | \returns current grayscale value (0 - 4095) for channel 223 | \see set */ 224 | uint16_t Tlc5940::get(TLC_CHANNEL_TYPE channel) 225 | { 226 | TLC_CHANNEL_TYPE index8 = (NUM_TLCS * 16 - 1) - channel; 227 | uint8_t *index12p = tlc_GSData + ((((uint16_t)index8) * 3) >> 1); 228 | return (index8 & 1)? // starts in the middle 229 | (((uint16_t)(*index12p & 15)) << 8) | // upper 4 bits 230 | *(index12p + 1) // lower 8 bits 231 | : // starts clean 232 | (((uint16_t)(*index12p)) << 4) | // upper 8 bits 233 | ((*(index12p + 1) & 0xF0) >> 4); // lower 4 bits 234 | // that's probably the ugliest ternary operator I've ever created. 235 | } 236 | 237 | /** Sets all channels to value. 238 | \param value grayscale value (0 - 4095) */ 239 | void Tlc5940::setAll(uint16_t value) 240 | { 241 | uint8_t firstByte = value >> 4; 242 | uint8_t secondByte = (value << 4) | (value >> 8); 243 | uint8_t *p = tlc_GSData; 244 | while (p < tlc_GSData + NUM_TLCS * 24) { 245 | *p++ = firstByte; 246 | *p++ = secondByte; 247 | *p++ = (uint8_t)value; 248 | } 249 | } 250 | 251 | #if VPRG_ENABLED 252 | 253 | /** \addtogroup ReqVPRG_ENABLED 254 | From the \ref CoreFunctions "Core Functions": 255 | - \link Tlc5940::setAllDC Tlc.setAllDC(uint8_t value(0-63)) \endlink - sets 256 | all the dot correction data to value */ 257 | /* @{ */ 258 | 259 | /** Sets the dot correction for all channels to value. The dot correction 260 | value correspondes to maximum output current by 261 | \f$\displaystyle I_{OUT_n} = I_{max} \times \frac{DCn}{63} \f$ 262 | where 263 | - \f$\displaystyle I_{max} = \frac{1.24V}{R_{IREF}} \times 31.5 = 264 | \frac{39.06}{R_{IREF}} \f$ 265 | - DCn is the dot correction value for channel n 266 | \param value (0-63) */ 267 | void Tlc5940::setAllDC(uint8_t value) 268 | { 269 | tlc_dcModeStart(); 270 | 271 | uint8_t firstByte = value << 2 | value >> 4; 272 | uint8_t secondByte = value << 4 | value >> 2; 273 | uint8_t thirdByte = value << 6 | value; 274 | 275 | for (TLC_CHANNEL_TYPE i = 0; i < NUM_TLCS * 12; i += 3) { 276 | tlc_shift8(firstByte); 277 | tlc_shift8(secondByte); 278 | tlc_shift8(thirdByte); 279 | } 280 | pulse_pin(XLAT_PORT, XLAT_PIN); 281 | 282 | tlc_dcModeStop(); 283 | } 284 | 285 | /* @} */ 286 | 287 | #endif 288 | 289 | #if XERR_ENABLED 290 | 291 | /** Checks for shorted/broken LEDs reported by any of the TLCs. 292 | \returns 1 if a TLC is reporting an error, 0 otherwise. */ 293 | uint8_t Tlc5940::readXERR(void) 294 | { 295 | return ((XERR_PINS & _BV(XERR_PIN)) == 0); 296 | } 297 | 298 | #endif 299 | 300 | /* @} */ 301 | 302 | #if DATA_TRANSFER_MODE == TLC_BITBANG 303 | 304 | /** Sets all the bit-bang pins to output */ 305 | void tlc_shift8_init(void) 306 | { 307 | SIN_DDR |= _BV(SIN_PIN); // SIN as output 308 | SCLK_DDR |= _BV(SCLK_PIN); // SCLK as output 309 | SCLK_PORT &= ~_BV(SCLK_PIN); 310 | } 311 | 312 | /** Shifts a byte out, MSB first */ 313 | void tlc_shift8(uint8_t byte) 314 | { 315 | for (uint8_t bit = 0x80; bit; bit >>= 1) { 316 | if (bit & byte) { 317 | SIN_PORT |= _BV(SIN_PIN); 318 | } else { 319 | SIN_PORT &= ~_BV(SIN_PIN); 320 | } 321 | pulse_pin(SCLK_PORT, SCLK_PIN); 322 | } 323 | } 324 | 325 | #elif DATA_TRANSFER_MODE == TLC_SPI 326 | 327 | /** Initializes the SPI module to double speed (f_osc / 2) */ 328 | void tlc_shift8_init(void) 329 | { 330 | SIN_DDR |= _BV(SIN_PIN); // SPI MOSI as output 331 | SCLK_DDR |= _BV(SCLK_PIN); // SPI SCK as output 332 | TLC_SS_DDR |= _BV(TLC_SS_PIN); // SPI SS as output 333 | 334 | SCLK_PORT &= ~_BV(SCLK_PIN); 335 | 336 | SPSR = _BV(SPI2X); // double speed (f_osc / 2) 337 | SPCR = _BV(SPE) // enable SPI 338 | | _BV(MSTR); // master mode 339 | } 340 | 341 | /** Shifts out a byte, MSB first */ 342 | void tlc_shift8(uint8_t byte) 343 | { 344 | SPDR = byte; // starts transmission 345 | while (!(SPSR & _BV(SPIF))) 346 | ; // wait for transmission complete 347 | } 348 | 349 | #endif 350 | 351 | #if VPRG_ENABLED 352 | 353 | /** Switches to dot correction mode and clears any waiting grayscale latches.*/ 354 | void tlc_dcModeStart(void) 355 | { 356 | disable_XLAT_pulses(); // ensure that no latches happen 357 | clear_XLAT_interrupt(); // (in case this was called right after update) 358 | tlc_needXLAT = 0; 359 | VPRG_PORT |= _BV(VPRG_PIN); // dot correction mode 360 | } 361 | 362 | /** Switches back to grayscale mode. */ 363 | void tlc_dcModeStop(void) 364 | { 365 | VPRG_PORT &= ~_BV(VPRG_PIN); // back to grayscale mode 366 | firstGSInput = 1; 367 | } 368 | 369 | #endif 370 | 371 | /** Preinstantiated Tlc variable. */ 372 | Tlc5940 Tlc; 373 | -------------------------------------------------------------------------------- /src/AlaLedRgb.cpp: -------------------------------------------------------------------------------- 1 | #include "Ala.h" 2 | #include "AlaLedRgb.h" 3 | 4 | #include "ExtNeoPixel.h" 5 | #include "ExtTlc5940.h" 6 | 7 | 8 | 9 | 10 | AlaLedRgb::AlaLedRgb() 11 | { 12 | // set default values 13 | 14 | maxOut = 0xFFFFFF; 15 | speed = 1000; 16 | animSeqLen = 0; 17 | lastRefreshTime = 0; 18 | refreshMillis = 1000/50; 19 | pxPos = NULL; 20 | pxSpeed = NULL; 21 | } 22 | 23 | 24 | void AlaLedRgb::initPWM(byte pinRed, byte pinGreen, byte pinBlue) 25 | { 26 | byte *pins_ = (byte *)malloc(3); 27 | pins_[0] = pinRed; 28 | pins_[1] = pinGreen; 29 | pins_[2] = pinBlue; 30 | 31 | initPWM(1, pins_); 32 | } 33 | 34 | void AlaLedRgb::initPWM(int numLeds, byte *pins) 35 | { 36 | this->driver = ALA_PWM; 37 | this->numLeds = numLeds; 38 | this->pins = pins; 39 | 40 | for (int x=0; x<3*numLeds ; x++) 41 | { 42 | pinMode(pins[x], OUTPUT); 43 | } 44 | 45 | // allocate and clear leds array 46 | leds = (AlaColor *)malloc(3*numLeds); 47 | memset(leds, 0, 3*numLeds); 48 | } 49 | 50 | void AlaLedRgb::initTLC5940(int numLeds, byte *pins) 51 | { 52 | this->driver = ALA_TLC5940; 53 | this->numLeds = numLeds; 54 | this->pins = pins; 55 | 56 | // allocate and clear leds array 57 | leds = (AlaColor *)malloc(3*numLeds); 58 | memset(leds, 0, 3*numLeds); 59 | 60 | // call Tlc.init only once 61 | static bool isTlcInit = false; 62 | if(!isTlcInit) 63 | { 64 | Tlc.init(0); 65 | isTlcInit=true; 66 | } 67 | } 68 | 69 | void AlaLedRgb::initWS2812(int numLeds, byte pin, byte type) 70 | { 71 | this->driver = ALA_WS2812; 72 | this->numLeds = numLeds; 73 | this->pins = 0; 74 | 75 | // allocate and clear leds array 76 | leds = (AlaColor *)malloc(3*numLeds); 77 | memset(leds, 0, 3*numLeds); 78 | 79 | neopixels = new Adafruit_NeoPixel(numLeds, pin, type); 80 | 81 | neopixels->begin(); 82 | } 83 | 84 | 85 | 86 | void AlaLedRgb::setBrightness(AlaColor maxOut) 87 | { 88 | this->maxOut = maxOut; 89 | } 90 | 91 | void AlaLedRgb::setRefreshRate(int refreshRate) 92 | { 93 | this->refreshMillis = 1000/refreshRate; 94 | } 95 | 96 | int AlaLedRgb::getCurrentRefreshRate() 97 | { 98 | return refreshRate; 99 | } 100 | 101 | 102 | void AlaLedRgb::setAnimation(int animation, long speed, AlaColor color, bool isSeq) 103 | { 104 | // is there any change? 105 | if (this->animation == animation && this->speed == speed && this->palette.numColors == 1 && this->palette.colors[0] == color) 106 | return; 107 | 108 | // delete any previously allocated array 109 | if (pxPos!=NULL) 110 | { delete[] pxPos; pxPos=NULL; } 111 | if (pxSpeed!=NULL) 112 | { delete[] pxSpeed; pxSpeed=NULL; } 113 | 114 | this->animation = animation; 115 | this->speed = speed; 116 | 117 | this->palette.numColors = 1; 118 | // TODO is this a memory leak? 119 | this->palette.colors = (AlaColor*)malloc(3); 120 | this->palette.colors[0] = color; 121 | 122 | if (!isSeq) 123 | animSeqLen=0; 124 | setAnimationFunc(animation); 125 | animStartTime = millis(); 126 | } 127 | 128 | 129 | void AlaLedRgb::setAnimation(int animation, long speed, AlaPalette palette, bool isSeq) 130 | { 131 | // is there any change? 132 | if (this->animation == animation && this->speed == speed && this->palette == palette) 133 | return; 134 | 135 | // delete any previously allocated array 136 | if (pxPos!=NULL) 137 | { delete[] pxPos; pxPos=NULL; } 138 | if (pxSpeed!=NULL) 139 | { delete[] pxSpeed; pxSpeed=NULL; } 140 | 141 | this->animation = animation; 142 | this->speed = speed; 143 | this->palette = palette; 144 | 145 | if (!isSeq) 146 | animSeqLen=0; 147 | setAnimationFunc(animation); 148 | animStartTime = millis(); 149 | } 150 | 151 | 152 | void AlaLedRgb::setAnimation(AlaSeq animSeq[]) 153 | { 154 | this->animSeq = animSeq; 155 | 156 | // initialize animSeqDuration and animSeqLen variables 157 | animSeqDuration = 0; 158 | for(animSeqLen=0; animSeq[animSeqLen].animation!=ALA_ENDSEQ; animSeqLen++) 159 | { 160 | animSeqDuration = animSeqDuration + animSeq[animSeqLen].duration; 161 | } 162 | animSeqStartTime = millis(); 163 | setAnimation(animSeq[0].animation, animSeq[0].speed, animSeq[0].palette, true); 164 | } 165 | 166 | void AlaLedRgb::setSpeed(long speed) 167 | { 168 | this->speed = speed; 169 | animStartTime = millis(); 170 | } 171 | 172 | void AlaLedRgb::setColor(AlaColor color) 173 | { 174 | this->palette.colors[0] = color; 175 | } 176 | 177 | int AlaLedRgb::getAnimation() 178 | { 179 | return animation; 180 | } 181 | 182 | 183 | bool AlaLedRgb::runAnimation() 184 | { 185 | if(animation == ALA_STOPSEQ) 186 | return true; 187 | 188 | // skip the refresh if not enough time has passed since last update 189 | unsigned long cTime = millis(); 190 | if (cTime < lastRefreshTime + refreshMillis) 191 | return false; 192 | 193 | // calculate real refresh rate 194 | refreshRate = 1000/(cTime - lastRefreshTime); 195 | 196 | lastRefreshTime = cTime; 197 | 198 | // if it's a sequence we have to calculate the current animation 199 | if (animSeqLen != 0) 200 | { 201 | long c = 0; 202 | long t = (cTime-animSeqStartTime) % animSeqDuration; 203 | for(int i=0; i=c && t<(c+animSeq[i].duration)) 206 | { 207 | setAnimation(animSeq[i].animation, animSeq[i].speed, animSeq[i].palette, true); 208 | break; 209 | } 210 | c = c + animSeq[i].duration; 211 | } 212 | } 213 | 214 | 215 | // run the animantion calculation 216 | if (animFunc != NULL) 217 | (this->*animFunc)(); 218 | 219 | // update leds 220 | if(driver==ALA_PWM) 221 | { 222 | for(int i=0; i>8); 227 | analogWrite(pins[j+1], (leds[i].g*maxOut.g)>>8); 228 | analogWrite(pins[j+2], (leds[i].b*maxOut.b)>>8); 229 | } 230 | } 231 | else if(driver==ALA_TLC5940) 232 | { 233 | // TLC5940 maximum output is 4095 so shifts only 4 bits 234 | for(int i=0; i>4); 238 | Tlc.set(pins[j+1], (leds[i].g*maxOut.g)>>4); 239 | Tlc.set(pins[j+2], (leds[i].b*maxOut.b)>>4); 240 | } 241 | Tlc.update(); 242 | } 243 | else if(driver==ALA_WS2812) 244 | { 245 | // this is not really so smart... 246 | for(int i=0; isetPixelColor(i, neopixels->Color((leds[i].r*maxOut.r)>>8, (leds[i].g*maxOut.g)>>8, (leds[i].b*maxOut.b)>>8)); 248 | 249 | neopixels->show(); 250 | } 251 | 252 | return true; 253 | } 254 | 255 | 256 | /////////////////////////////////////////////////////////////////////////////// 257 | 258 | void AlaLedRgb::setAnimationFunc(int animation) 259 | { 260 | 261 | switch(animation) 262 | { 263 | case ALA_ON: animFunc = &AlaLedRgb::on; break; 264 | case ALA_OFF: animFunc = &AlaLedRgb::off; break; 265 | case ALA_BLINK: animFunc = &AlaLedRgb::blink; break; 266 | case ALA_BLINKALT: animFunc = &AlaLedRgb::blinkAlt; break; 267 | case ALA_SPARKLE: animFunc = &AlaLedRgb::sparkle; break; 268 | case ALA_SPARKLE2: animFunc = &AlaLedRgb::sparkle2; break; 269 | case ALA_STROBO: animFunc = &AlaLedRgb::strobo; break; 270 | case ALA_CYCLECOLORS: animFunc = &AlaLedRgb::cycleColors; break; 271 | 272 | case ALA_PIXELSHIFTRIGHT: animFunc = &AlaLedRgb::pixelShiftRight; break; 273 | case ALA_PIXELSHIFTLEFT: animFunc = &AlaLedRgb::pixelShiftLeft; break; 274 | case ALA_PIXELBOUNCE: animFunc = &AlaLedRgb::pixelBounce; break; 275 | case ALA_PIXELSMOOTHSHIFTRIGHT: animFunc = &AlaLedRgb::pixelSmoothShiftRight; break; 276 | case ALA_PIXELSMOOTHSHIFTLEFT: animFunc = &AlaLedRgb::pixelSmoothShiftLeft; break; 277 | case ALA_PIXELSMOOTHBOUNCE: animFunc = &AlaLedRgb::pixelSmoothBounce; break; 278 | case ALA_COMET: animFunc = &AlaLedRgb::comet; break; 279 | case ALA_COMETCOL: animFunc = &AlaLedRgb::cometCol; break; 280 | case ALA_MOVINGBARS: animFunc = &AlaLedRgb::movingBars; break; 281 | case ALA_MOVINGGRADIENT: animFunc = &AlaLedRgb::movingGradient; break; 282 | case ALA_LARSONSCANNER: animFunc = &AlaLedRgb::larsonScanner; break; 283 | case ALA_LARSONSCANNER2: animFunc = &AlaLedRgb::larsonScanner2; break; 284 | 285 | case ALA_FADEIN: animFunc = &AlaLedRgb::fadeIn; break; 286 | case ALA_FADEOUT: animFunc = &AlaLedRgb::fadeOut; break; 287 | case ALA_FADEINOUT: animFunc = &AlaLedRgb::fadeInOut; break; 288 | case ALA_GLOW: animFunc = &AlaLedRgb::glow; break; 289 | case ALA_PLASMA: animFunc = &AlaLedRgb::plasma; break; 290 | case ALA_PIXELSFADECOLORS: animFunc = &AlaLedRgb::pixelsFadeColors; break; 291 | case ALA_FADECOLORS: animFunc = &AlaLedRgb::fadeColors; break; 292 | case ALA_FADECOLORSLOOP: animFunc = &AlaLedRgb::fadeColorsLoop; break; 293 | 294 | case ALA_FIRE: animFunc = &AlaLedRgb::fire; break; 295 | case ALA_BOUNCINGBALLS: animFunc = &AlaLedRgb::bouncingBalls; break; 296 | case ALA_BUBBLES: animFunc = &AlaLedRgb::bubbles; break; 297 | 298 | default: animFunc = &AlaLedRgb::off; 299 | } 300 | 301 | } 302 | 303 | 304 | void AlaLedRgb::on() 305 | { 306 | for(int i=0; i7, 3-11, 4-14 504 | float t = getStepFloat(animStartTime, speed, 2*numLeds+(l*4-1)); 505 | AlaColor c = palette.getPalColor(getStepFloat(animStartTime, speed, palette.numColors)); 506 | 507 | for(int x=0; x=3; k--) 677 | { 678 | heat[k] = ((int)heat[k - 1] + (int)heat[k - 2] + (int)heat[k - 3] ) / 3; 679 | } 680 | 681 | // Step 3. Randomly ignite new 'sparks' of heat near the bottom 682 | if(random(255) < SPARKING) 683 | { 684 | int y = random(7); 685 | heat[y] = min(heat[y] + random(160, 255), 255); 686 | } 687 | 688 | // Step 4. Map from heat cells to LED colors 689 | for(int j=0; j-0.04 and pxSpeed[i]<0 and pxPos[i]>0 and pxPos[i]<0.1) 722 | pxSpeed[i]=(0.09)-((float)random(10)/1000); 723 | 724 | pxPos[i] = pxPos[i] + pxSpeed[i]; 725 | if(pxPos[i]>=1) 726 | { 727 | pxPos[i]=1; 728 | } 729 | if(pxPos[i]<0) 730 | { 731 | pxPos[i]=-pxPos[i]; 732 | pxSpeed[i]=-0.91*pxSpeed[i]; 733 | } 734 | 735 | pxSpeed[i] = pxSpeed[i]-speedReduction; 736 | } 737 | 738 | for (int x=0; x=1) 777 | { 778 | pxPos[i]=0; 779 | pxSpeed[i]=0; 780 | } 781 | if(random(20)==0 and pxPos[i]==0) 782 | { 783 | pxPos[i]=0.0001; 784 | pxSpeed[i]=0.0001; 785 | } 786 | if(pxPos[i]>0) 787 | { 788 | pxPos[i] = pxPos[i] + pxSpeed[i]; 789 | pxSpeed[i] = pxSpeed[i] + speedDelta; 790 | } 791 | } 792 | 793 | for (int x=0; x0) 800 | { 801 | int p = mapfloat(pxPos[i], 0, 1, 0, numLeds-1); 802 | AlaColor c = palette.colors[i].scale(1-(float)random(10)/30); // add a little flickering 803 | leds[p] = c; 804 | } 805 | } 806 | 807 | } 808 | 809 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | --------------------------------------------------------------------------------