Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
963 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* inoise8_fire | ||
* | ||
* By: Andrew Tuline | ||
* | ||
* Date: January, 2017 | ||
* | ||
* This super short sketch (just two lines to the algorithm) displays fire thanks to FastLED's Perlin Noise function and Palettes. | ||
* | ||
* It needs some tweaking in order to work across a wide range of NUM_LED values, but looks pretty good at 60. | ||
* | ||
*/ | ||
|
||
|
||
#include "FastLED.h" | ||
|
||
#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 WS2801 or APA102. | ||
#define COLOR_ORDER BGR // It's GRB for WS2812 and BGR for APA102. | ||
#define LED_TYPE APA102 // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit. | ||
#define NUM_LEDS 60 // Number of LED's. | ||
|
||
// Global variables can be changed on the fly. | ||
uint8_t max_bright = 128; // Overall brightness definition. It can be changed on the fly. | ||
|
||
struct CRGB leds[NUM_LEDS]; | ||
|
||
CRGBPalette16 currentPalette; | ||
|
||
uint32_t xscale = 20; // How far apart they are | ||
uint32_t yscale = 3; // How fast they move | ||
uint8_t index = 0; | ||
|
||
|
||
|
||
void setup() { | ||
|
||
Serial.begin(57600); // Initialize serial port for debugging. | ||
delay(1000); // Soft startup to ease the flow of electrons. | ||
|
||
LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2801 or APA102 | ||
// 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 Power management set at 5V, 500mA. | ||
|
||
currentPalette = CRGBPalette16( | ||
CRGB::Black, CRGB::Black, CRGB::Black, CHSV(0, 255,4), | ||
CHSV(0, 255, 8), CRGB::Red, CRGB::Red, CRGB::Red, | ||
CRGB::DarkOrange,CRGB::Orange, CRGB::Orange, CRGB::Orange, | ||
CRGB::Yellow, CRGB::Yellow, CRGB::Gray, CRGB::Gray); | ||
} // setup() | ||
|
||
|
||
|
||
void loop() { | ||
|
||
inoise8_fire(); // I am the god of hell fire and I bring you . . . | ||
FastLED.show(); | ||
|
||
} // loop() | ||
|
||
|
||
|
||
void inoise8_fire() { | ||
|
||
for(int i = 0; i < NUM_LEDS; i++) { | ||
index = inoise8(i*xscale,millis()*yscale*NUM_LEDS/255); // X location is constant, but we move along the Y at the rate of millis() | ||
leds[i] = ColorFromPalette(currentPalette, min(i*(index)>>6, 255), i*255/NUM_LEDS, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED. | ||
} // The higher the value of i => the higher up the palette index (see palette definition). | ||
// Also, the higher the value of i => the brighter the LED. | ||
} // inoise8_fire() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* inoise8_pal_demo | ||
* | ||
* By: Andrew Tuline | ||
* | ||
* Date: August, 2016 | ||
* | ||
* This short sketch demonstrates some of the functions of FastLED, including: | ||
* | ||
* Perlin noise | ||
* Palettes | ||
* Palette blending | ||
* Alternatives to blocking delays | ||
* Beats (and not the Dr. Dre kind, but rather the sinewave kind) | ||
* | ||
* Refer to the FastLED noise.h and lib8tion.h routines for more information on these functions. | ||
* | ||
*/ | ||
|
||
|
||
#include "FastLED.h" | ||
|
||
#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 WS2801 or APA102. | ||
#define COLOR_ORDER BGR // It's GRB for WS2812 and BGR for APA102. | ||
#define LED_TYPE APA102 // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit. | ||
#define NUM_LEDS 60 // Number of LED's. | ||
|
||
|
||
// Global variables can be changed on the fly. | ||
uint8_t max_bright = 128; // Overall brightness definition. It can be changed on the fly. | ||
|
||
struct CRGB leds[NUM_LEDS]; | ||
|
||
CRGBPalette16 currentPalette(CRGB::Black); | ||
CRGBPalette16 targetPalette(OceanColors_p); | ||
TBlendType currentBlending; // NOBLEND or LINEARBLEND | ||
|
||
static int16_t dist; // A random number for our noise generator. | ||
uint16_t xscale = 30; // Wouldn't recommend changing this on the fly, or the animation will be really blocky. | ||
uint16_t yscale = 30; // Wouldn't recommend changing this on the fly, or the animation will be really blocky. | ||
uint8_t maxChanges = 24; // Value for blending between palettes. | ||
|
||
|
||
|
||
void setup() { | ||
|
||
Serial.begin(57600); // Initialize serial port for debugging. | ||
delay(1000); // Soft startup to ease the flow of electrons. | ||
|
||
// LEDS.addLeds<LED_TYPE,LED_DT,COLOR_ORDER>(leds,NUM_LEDS); | ||
LEDS.addLeds<LED_TYPE,LED_DT,LED_CK, COLOR_ORDER>(leds,NUM_LEDS); | ||
|
||
FastLED.setBrightness(max_bright); | ||
set_max_power_in_volts_and_milliamps(5, 500); // FastLED Power management set at 5V, 500mA. | ||
|
||
dist = random16(12345); // A semi-random number for our noise generator | ||
|
||
} // setup() | ||
|
||
|
||
|
||
void loop() { | ||
|
||
EVERY_N_MILLISECONDS(10) { | ||
uint8_t maxChanges = 24; | ||
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // AWESOME palette blending capability. | ||
fillnoise8(); // Update the LED array with noise at the new location | ||
} | ||
|
||
EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds. | ||
targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 192, random8(128,255)), CHSV(random8(), 255, random8(128,255))); | ||
} | ||
|
||
FastLED.show(); | ||
|
||
} // loop() | ||
|
||
|
||
|
||
void fillnoise8() { | ||
|
||
for(int i = 0; i < NUM_LEDS; i++) { // Just ONE loop to fill up the LED array as all of the pixels change. | ||
uint8_t index = inoise8(i*xscale, dist+i*yscale) % 255; // Get a value from the noise function. I'm using both x and y axis. | ||
leds[i] = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED. | ||
} | ||
|
||
dist += beatsin8(10,1,4); // Moving along the distance (that random number we started out with). Vary it a bit with a sine wave. | ||
// In some sketches, I've used millis() instead of an incremented counter. Works a treat. | ||
} // fillnoise8() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* juggle_pal | ||
* | ||
* Originally by: Mark Kriegsman | ||
* | ||
* Modified By: Andrew Tuline | ||
* | ||
* Date: February, 2015 | ||
* | ||
* Juggle just moves some balls back and forth. A single ball could be a Cylon effect. I've added several variables to this simple routine. | ||
* | ||
*/ | ||
|
||
|
||
#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 // Data pin to connect to the strip. | ||
#define LED_CK 11 // Clock pin for WS2801 or APA102. | ||
#define COLOR_ORDER BGR // It's GRB for WS2812 and BGR for APA102. | ||
#define LED_TYPE APA102 // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit. | ||
#define NUM_LEDS 60 // Number of LED's. | ||
|
||
// Global variables can be changed on the fly. | ||
uint8_t max_bright = 128; // Overall brightness definition. It can be changed on the fly. | ||
|
||
struct CRGB leds[NUM_LEDS]; // Initialize our LED array. | ||
|
||
CRGBPalette16 currentPalette; // Use palettes instead of direct CHSV or CRGB assignments | ||
CRGBPalette16 targetPalette; // Also support smooth palette transitioning | ||
TBlendType currentBlending; // NOBLEND or LINEARBLEND | ||
|
||
|
||
// Routine specific variables | ||
uint8_t numdots = 4; // Number of dots in use. | ||
uint8_t thisfade = 2; // How long should the trails be. Very low value = longer trails. | ||
uint8_t thisdiff = 16; // Incremental change in hue between each dot. | ||
uint8_t thishue = 0; // Starting hue. | ||
uint8_t curhue = 0; // The current hue | ||
uint8_t thissat = 255; // Saturation of the colour. | ||
uint8_t thisbright = 255; // How bright should the LED/display be. | ||
uint8_t thisbeat = 5; // Higher = faster movement. | ||
|
||
|
||
|
||
void setup() { | ||
|
||
Serial.begin(57600); // Initialize serial port for debugging. | ||
delay(1000); // Soft startup to ease the flow of electrons. | ||
|
||
// 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 | ||
|
||
currentPalette = CRGBPalette16(CRGB::Black); | ||
targetPalette = RainbowColors_p; | ||
currentBlending = LINEARBLEND; | ||
|
||
FastLED.setBrightness(max_bright); | ||
set_max_power_in_volts_and_milliamps(5, 1000); // FastLED power management set at 5V, 500mA. | ||
|
||
} // setup() | ||
|
||
|
||
|
||
void loop() { | ||
|
||
EVERY_N_MILLISECONDS(100) { // AWESOME palette blending capability provided as required. | ||
uint8_t maxChanges = 24; | ||
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); | ||
} | ||
|
||
ChangeMe(); | ||
juggle_pal(); | ||
FastLED.show(); // Power managed display of LED's. | ||
|
||
} // loop() | ||
|
||
|
||
|
||
void juggle_pal() { // Several colored dots, weaving in and out of sync with each other | ||
|
||
curhue = thishue; // Reset the hue values. | ||
fadeToBlackBy(leds, NUM_LEDS, thisfade); | ||
|
||
for( int i = 0; i < numdots; i++) { | ||
leds[beatsin16(thisbeat+i+numdots,0,NUM_LEDS)] += ColorFromPalette(currentPalette, curhue , thisbright, currentBlending); // Munge the values and pick a colour from the palette | ||
curhue += thisdiff; | ||
} | ||
|
||
} // juggle_pal() | ||
|
||
|
||
|
||
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) % 30; // IMPORTANT!!! Change '30' 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: numdots = 1; thisbeat = 20; thisdiff = 16; thisfade = 2; thishue = 0; break; // You can change values here, one at a time , or altogether. | ||
case 10: numdots = 4; thisbeat = 10; thisdiff = 16; thisfade = 8; thishue = 128; break; | ||
case 20: numdots = 8; thisbeat = 3; thisdiff = 0; thisfade = 8; thishue=random8(); break; // Only gets called once, and not continuously for the next several seconds. Therefore, no rainbows. | ||
case 30: break; | ||
} | ||
} | ||
|
||
} // ChangeMe() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.