Skip to content

Commit

Permalink
More demos uploaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
atuline committed Feb 3, 2017
1 parent 152c57f commit 917f68b
Show file tree
Hide file tree
Showing 13 changed files with 963 additions and 158 deletions.
78 changes: 78 additions & 0 deletions inoise8_fire/inoise8_fire.ino
@@ -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()

94 changes: 94 additions & 0 deletions inoise8_pal_demo/inoise8_pal_demo.ino
@@ -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()
113 changes: 113 additions & 0 deletions juggle_pal/juggle_pal.ino
@@ -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()

61 changes: 40 additions & 21 deletions lightnings/lightnings.ino
@@ -1,11 +1,15 @@
// Lightnings is a program that lets you make an LED strip look like a 1D cloud of lightning
//
// Original by: Daniel Wilson, 2014
//
// Modified by: Andrew Tuline 2015
//
// This modified version creates lightning along various sections of the strip. Looks great inside my poly fill constructed cloud.
//
/* lightnings
*
* By: Daniel Wilson
*
* Modified by: Andrew Tuline
*
* Date: January, 2017
*
* Lightnings is a program that lets you make an LED strip look like a 1D cloud of lightning.
* I wouldn't use this code in conjunction with any controls because it uses those nasty blocking delays which I haven't bothered to remove.
*
*/

#include "FastLED.h"

Expand All @@ -18,10 +22,10 @@
#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 change LEDS.addLeds.
#define NUM_LEDS 20 // Number of LED's.
#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.
uint8_t max_bright = 255; // Overall brightness definition. It can be changed on the fly.

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

Expand All @@ -33,28 +37,43 @@ uint8_t ledstart; // Starting locati
uint8_t ledlen; // Length of a flash



void setup() {
delay(1000); // allows reprogramming if accidently blowing power w/leds

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 WS2812
LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2801 or APA102

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

} // setup()



void loop() {
ledstart = random8(NUM_LEDS); // Determine starting location of flash
ledlen = random8(NUM_LEDS-ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)

ledstart = random8(NUM_LEDS); // Determine starting location of flash
ledlen = random8(NUM_LEDS-ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)

for (int flashCounter = 0; flashCounter < random8(3,flashes); flashCounter++) {
if(flashCounter == 0) dimmer = 5; // the brightness of the leader is scaled down by a factor of 5
else dimmer = random8(1,3); // return strokes are brighter than the leader
if(flashCounter == 0) dimmer = 5; // the brightness of the leader is scaled down by a factor of 5
else dimmer = random8(1,3); // return strokes are brighter than the leader

fill_solid(leds+ledstart,ledlen,CHSV(255, 0, 255/dimmer));
FastLED.show(); // Show a section of LED's
delay(random8(4,10)); // each flash only lasts 4-10 milliseconds
fill_solid(leds+ledstart,ledlen,CHSV(255,0,0)); // Clear the section of LED's
FastLED.show();
if (flashCounter == 0) delay (150); // longer delay until next flash after the leader
delay(50+random8(100)); // shorter delay between strokes
delay(random8(4,10)); // each flash only lasts 4-10 milliseconds
fill_solid(leds+ledstart,ledlen,CHSV(255,0,0)); // Clear the section of LED's
FastLED.show();

if (flashCounter == 0) delay (150); // longer delay until next flash after the leader

delay(50+random8(100)); // shorter delay between strokes
} // for()
delay(random8(frequency)*100); // delay between strikes

delay(random8(frequency)*100); // delay between strikes

} // loop()

0 comments on commit 917f68b

Please sign in to comment.