Skip to content

Commit

Permalink
Some cool updates.
Browse files Browse the repository at this point in the history
atuline committed Jul 26, 2015
1 parent f8ac63c commit b7839a3
Showing 21 changed files with 300 additions and 135 deletions.
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,23 +10,22 @@
!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!


If this is your first foray into addressable LED's, then start off with a small strip of < 20 LED's. Long strips can exhibit some significant power issues, so start off small and work up to longer strips.
If this is your first foray into addressable LED's, then start off with a small strip of < 20 LED's. Long strips require careful power management planning, so start off small and then work up to longer strips.

Before attempting to use these demos, you should compile and run the examples found with the latest version of the FastLED library, available at:
Before attempting to use these demos, make sure you can compile and run the examples found with the latest development version of the FastLED library, currently 3.1.

https://github.com/FastLED/FastLED
The FastLED Google+ community is at https://plus.google.com/communities/109127054924227823508

In some cases, you may need to use the latest development version of FastLED.
Finally, before looking for some support, have a look at my FastLED FAQ at http://www.tuline.com/dru/content/my-fastled-support-faq



##Introduction

Here's several COMPLETELY re-written display sequences for FastLED for a single strand of RGB LED's, such as Neopixels, WS2812B, WS2801 or APA102. Each should compile and run separately and have been tested on an Arduino UNO and Nano 3.0.
##Introduction

In an older version, I had several demos that used nested for loops, required a lot of code, weren't highly customizable. Except for some really cool ones, most of those have now been replaced. For instance, two_sin() replaces several 'marching' type sequences and supports several variables to change colour, phase, direction, brightness and so on. Likewise, pop_fade_demo replaces several twinkling sequences.
Here's several display sequences for FastLED for a single strand of RGB LED's, such as Neopixels/WS2812, WS2801 or DotStars/APA102. Each should compile and run separately and have been tested on an Arduino Nano.

The new sequences are now designed to be loop/non-blocking delay friendly. They perform some simple calculations, update the LED array and then then return back to the loop to SHOW the LED's and then continue on to the next iteration.
These sequences are designed to be loop/non-blocking delay friendly. They perform some simple calculations, update the LED array, return back to the loop to SHOW the LED's and then continue on to the next iteration.

In addition to several standalone demos, I have included a display template as well as aalight and aainfra, which support multiple display sequences, a demo mode, keyboard, IR remote and updated pushbutton control.

@@ -36,30 +35,27 @@ I have also included a few sound reactive sequences, most notably fht_log, which

**aatemplate.ino** - A standard display template which can be re-used.

**aalight.ino** - Runs on an Arduino connected to an LED strip. Compile aalight.ino, and it will include the other ino files in the directory. The structure for this code is based on funkboxing LED. In addition, to the FastLED library, it also requires a couple of other 3rd party libraries to support pushbutton and IR remote control.
**aalight.ino** - Runs on an Arduino connected to an LED strip. Compile aalight.ino, and it will include the other files in the directory. The overall structure for this code is based on funkboxing LED. In addition, to the FastLED library, it also requires a couple of other 3rd party libraries to support pushbutton and IR remote control.

**aainfra.ino** - Runs on a 2nd Arduino with an IR sensor attached. Compile aainfra.ino and connect Tx of the 2nd Arduino to Rx of the first one. You will need to disconnect that in order to program the Arduinos.

See aalight.ino comment section for more information on how to use this. Also see aalight.png for a breadboard layout.


The awesome FastLED Library is available from: [fastled.io](http://fastled.io/)

Download FastLED from: [github.com/FastLED/FastLED](https://github.com/FastLED/FastLED)

Information about the awesome FastLED Library is available from: [fastled.io](http://fastled.io/)

## Update
Download FastLED (select version 3.1) from: [github.com/FastLED/FastLED](https://github.com/FastLED/FastLED)

I've replaced a pile of if statement with switch statement for the demo loops.

## Adding to the Library

In order for me to add sequences to the library, my expectation is that they:

* Run quickly (no nested for loops with delay statements).
* Be called with many different parameters.
* Can be called with many different parameters.
* Be short.
* Use 8 or 16 bit math. No floating point.
* Preference is given to time based rather than delay based code.


----------------------------------------------------------
2 changes: 1 addition & 1 deletion aalight/aalight.ino
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ Power Supplies I've Used
Libraries Required
- FastLED library from https://github.com/FastLED/FastLED
- FastLED library (get 3.1) from https://github.com/FastLED/FastLED
- Nico Hood's IRL library from https://github.com/NicoHood/IRLremote
- JChristensen's Button Library from https://github.com/JChristensen/Button
63 changes: 33 additions & 30 deletions aatemplate/aatemplate.ino
Original file line number Diff line number Diff line change
@@ -3,69 +3,73 @@
By: Andrew Tuline
Date: Oct, 2014
Date: July, 2015
This is a simple FastLED display sequence template. This template also includes a time (rather than loop) based demo sequencer as well as a frame rate counter.
This is a simple non-blocking FastLED display sequence template.
Rather than use the standard 'FastLED.show()', I'm using the Power managed show, in order to ensure we don't exceed maximum current draw.
FastLED is available at https://github.com/FastLED/FastLED
*/


#include "FastLED.h" // FastLED library.

#include "FastLED.h" // FastLED library. Please use the latest development version.

#if FASTLED_VERSION < 3001000 // Add this if you want to ensure they're using a minimum version of FastLED
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
#endif


// Fixed definitions cannot change on the fly.
#define LED_DT 12 // Data pin to connect to the strip.
#define LED_CK 11
#define COLOR_ORDER BGR // It's GRB for WS2812B
#define LED_TYPE APA102 // What kind of strip are you using (WS2801, WS2812B or APA102)?
#define LED_CK 11 // Clock pin for WS2801 or APA102.
#define COLOR_ORDER GBR // Are they GRB for WS2812 and GBR for APA102.
#define LED_TYPE APA102 // Using APA102, WS2812, WS2801. Don't forget to change LEDS.addLeds.
#define NUM_LEDS 20 // Number of LED's.

// Initialize changeable global variables.
uint8_t max_bright = 128; // Overall brightness definition. It can be changed on the fly.
// Global variables can be changed on the fly.
uint8_t max_bright = 64; // Overall brightness definition. It can be changed on the fly.

struct CRGB leds[NUM_LEDS]; // Initialize our LED array.


// Define variables used by the sequences.
int twinkrate = 100; // The higher the value, the lower the number of twinkles.
uint8_t thisdelay = 20; // A delay value for the sequence(s).
uint8_t thisdelay = 60; // A delay value for the sequence(s).
uint8_t thisfade = 8; // How quickly does it fade? Lower = slower fade rate.
uint8_t thishue = 50; // The hue.
uint8_t thissat = 100; // The saturation, where 255 = brilliant colours.
uint8_t thisbri = 255; // Brightness of a sequence.
bool randhue = 0; // Do we want random colours all the time? 1 = yes.



void setup() {
delay(1000); // Power-up safety delay or something like that.
Serial.begin(57600); // Setup debug capabilities, make sure your IDE speed matches
delay(3000); // Power-up safety delay.
Serial.begin(57600); // Initialize serial port for debugging.

// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812B
LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2801 or APA102

random16_set_seed(4832); // Awesome randomizer left here for reference
random16_add_entropy(analogRead(2));

// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812

FastLED.setBrightness(max_bright);
set_max_power_in_volts_and_milliamps(5, 500); // FastLED 2.1 Power management set at 5V, 500mA.
set_max_power_in_volts_and_milliamps(5, 500); // FastLED Power management set at 5V, 500mA. This is OPTIONAL!!!
} // setup()



void loop () {
ChangeMe(); // Check the demo loop for changes to the variables.
twinkle(); // Call our sequence.
show_at_max_brightness_for_power(); // Power managed display of LED's.
delay_at_max_brightness_for_power(2.5*thisdelay); // Power managed FastLED delay.
Serial.println(LEDS.getFPS()); // Display frames per second on the serial monitor. Disable the delay in order to see how fast/efficient your sequence is.

EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence.
twinkle();
show_at_max_brightness_for_power();
}

Serial.println(LEDS.getFPS()); // Display frames per second on the serial monitor.
} // loop()



void twinkle() {
if (twinkrate < NUM_LEDS) twinkrate = NUM_LEDS; // Makes sure the twinkrate will cover ALL of the LED's as it's used as the maximum LED index value.
int i = random16(twinkrate); // A random number based on twinkrate. Higher number => fewer twinkles.
@@ -75,16 +79,15 @@ void twinkle() {
} // twinkle()



void ChangeMe() { // A time (rather than loop) based demo sequencer. This gives us full control over the length of each sequence.
uint8_t secondHand = (millis() / 1000) % 15; // IMPORTANT!!! Change '15' to a different value to change duration of the loop.
static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our 'debounce' variable.
if (lastSecond != secondHand) { // Debounce to make sure we're not repeating an assignment.
lastSecond = secondHand;
switch(secondHand) {
case 0: thisdelay = 20; randhue = 1; thissat=255; thisfade=16; thisdelay=50; twinkrate=20; break; // You can change values here, one at a time , or altogether.
case 5: thisdelay = 20; randhue = 0; thishue=128; thisfade=64; thisdelay=10; twinkrate=100; break;
case 10: thisdelay = 20; thishue=random16(0,64); twinkrate=40; break; // Only gets called once, and not continuously for the next several seconds. Therefore, no rainbows.
case 15: break; // Matches the '15' at the start of this function
}
if (secondHand == 0) {thisdelay = 60; randhue = 1; thissat=255; thisfade=16; twinkrate=20;} // You can change values here, one at a time , or altogether.
if (secondHand == 5) {thisdelay = 60; randhue = 0; thishue=128; thisfade=64; twinkrate=100;}
if (secondHand == 10) {thisdelay = 60; thishue=random16(0,64); twinkrate=40;} // Only gets called once, and not continuously for the next several seconds. Therefore, no rainbows.
}
} // ChangeMe()

76 changes: 76 additions & 0 deletions colorpal_beat/colorpal_beat.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* ColorPal_Beat
By: Andrew Tuline
Date: July, 2015
This routine uses FastLED beats and colour palettes with gradual palette cross fading. It doesn't require timers/delays except to change/fade between palettes on occasion.
*/


#include "FastLED.h"

#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif


#define LED_DT 12
#define LED_CK 11
#define NUM_LEDS 64
#define LED_TYPE APA102
#define COLOR_ORDER BGR

CRGB leds[NUM_LEDS];

uint8_t brightness = 128;

CRGBPalette16 currentPalette;
CRGBPalette16 targetPalette;
uint8_t maxChanges = 24;
TBlendType currentBlending;


void setup() {
delay(3000); // power-up safety delay

// FastLED.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // WS2812B
FastLED.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // WS2801 or APA102

FastLED.setBrightness(brightness);
set_max_power_in_volts_and_milliamps(5, 500); // FastLED Power management set at 5V, 500mA.

currentPalette = RainbowColors_p; // RainbowColors_p; CloudColors_p; PartyColors_p; LavaColors_p; HeatColors_p;
targetPalette = RainbowColors_p; // RainbowColors_p; CloudColors_p; PartyColors_p; LavaColors_p; HeatColors_p;
currentBlending = LINEARBLEND;
} //setup()


void loop() {
uint8_t beatA = beatsin8(5, 0, 255); // Starting hue
FillLEDsFromPaletteColors(beatA);
show_at_max_brightness_for_power(); // Power managed display.

EVERY_N_MILLISECONDS(100) { // FastLED based timer to update/display the sequence every 5 seconds.
nblendPaletteTowardPalette( currentPalette, targetPalette, maxChanges);
}

EVERY_N_MILLISECONDS(5000) { // FastLED based timer to update/display the sequence every 5 seconds.
SetupRandomPalette();
}
} //loop()


void FillLEDsFromPaletteColors(uint8_t colorIndex) {
uint8_t beatB = beatsin8(15, 10, 20); // Delta hue between LED's
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(currentPalette, colorIndex, 255, currentBlending);
colorIndex += beatB;
}
} //FillLEDsFromPaletteColors()


void SetupRandomPalette() {
targetPalette = CRGBPalette16(CHSV(random8(), 255, 32), CHSV(random8(), random8(64)+192, 255), CHSV(random8(), 255, 32), CHSV(random8(), 255, 255));
} // SetupRandomPalette()
21 changes: 16 additions & 5 deletions confetti/confetti.ino
Original file line number Diff line number Diff line change
@@ -5,14 +5,19 @@ By: Mark Kriegsman
Modified By: Andrew Tuline
Date: February 2015
Date: July 2015
Confetti flashes colours within a limited hue. It's been modified from Mark's original to support a few variables. It's a simple, but great looking routine.
*/


#include "FastLED.h" // FastLED library. Preferably the latest copy of FastLED 2.1.

#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif

// Fixed definitions cannot change on the fly.
#define LED_DT 12 // Data pin to connect to the strip.
#define LED_CK 11 // Clock pin for the strip.
@@ -25,6 +30,8 @@ uint8_t max_bright = 64; // Overall brightn

struct CRGB leds[NUM_LEDS]; // Initialize our LED array.

unsigned long previousMillis; // Store last time the strip was updated.


// Define variables used by the sequences.
uint8_t thisfade = 8; // How quickly does it fade? Lower = slower fade rate.
@@ -33,7 +40,8 @@ uint8_t thisinc = 1; // Incremental val
uint8_t thissat = 100; // The saturation, where 255 = brilliant colours.
uint8_t thisbri = 255; // Brightness of a sequence. Remember, max_bright is the overall limiter.
int huediff = 256; // Range of random #'s to use for hue
uint8_t thisdelay = 1; // We don't need much delay (if any)
uint8_t thisdelay = 5; // We don't need much delay (if any)


void setup() {
delay(1000); // Power-up safety delay or something like that.
@@ -49,12 +57,15 @@ void setup() {

void loop () {
ChangeMe(); // Check the demo loop for changes to the variables.
confetti(); // Call our sequence.
delay_at_max_brightness_for_power(thisdelay*2.5);
show_at_max_brightness_for_power(); // Power managed display of LED's.

EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence.
confetti();
show_at_max_brightness_for_power();
}
} // loop()



void confetti() { // random colored speckles that blink in and fade smoothly
fadeToBlackBy(leds, NUM_LEDS, thisfade); // Low values = slower fade.
int pos = random16(NUM_LEDS); // Pick an LED at random.
19 changes: 12 additions & 7 deletions dots/dots.ino
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ By: John Burroughs
Modified by: Andrew Tuline
Date: Oct, 2014
Date: July, 2015
This sequence moves a few LED's at different distances across the strip. This could be the basis for a routine that moves different dots with different routines.
@@ -17,6 +17,12 @@ You could also sequence through a palette with this as well.

#include "FastLED.h" // FastLED library.


#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif


// Fixed definitions cannot change on the fly.
#define LED_DT 12 // Serial data pin
#define LED_CK 11 // Serial clock pin for APA102 or WS2801
@@ -29,9 +35,8 @@ uint8_t max_bright = 128; // Overall brightn

struct CRGB leds[NUM_LEDS]; // Initialize our LED array.


// Define variables used by the sequences.
int thisdelay = 4; // A delay value for the sequence(s)
int thisdelay = 10; // A delay value for the sequence(s)
uint8_t count = 0; // Count up to 255 and then reverts to 0
uint8_t fadeval = 224; // Trail behind the LED's. Lower => faster fade.

@@ -49,10 +54,10 @@ void setup() {


void loop () {
dots();
show_at_max_brightness_for_power();
delay_at_max_brightness_for_power(thisdelay*2.5);
Serial.println(LEDS.getFPS());
EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence.
dots(); // Routine is still delay based, but at least it's now a non-blocking day.
show_at_max_brightness_for_power();
}
} // loop()


Loading
Oops, something went wrong.

0 comments on commit b7839a3

Please sign in to comment.