Still a newbie with newbie questions. Am running the DemoReel100 from the FastLED folder and I love the colorful patterns. The simple problem is I don’t understand the code very well. What I’d like to do is create a Theater Marquee type sketch. Whereby every 3rd, 4th even 8th LED chases on the strip. In my case I’m using 16LED NeoPixel type discs (rings). Can anyone point me as to where I might find an example that I can incorporate into the DemoReel100 sketch?
Thank you.
Okay I found Andrew Tuline’s aatemplate and various plug ins and I’ve pasted two effects but can only get one effect to work. What am I missing here?
/* Display Template for FastLED
By: Andrew Tuline
Date: July, 2015
This is a simple non-blocking FastLED display sequence template.
*/
#include “FastLED.h” // FastLED library. Please use the latest development version.
#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 7 // Data pin to connect to the strip.
//#define LED_CK 11 // Clock pin for WS2801 or APA102.
#define COLOR_ORDER RGB // It’s GRB for WS2812 and BGR for APA102.
#define LED_TYPE WS2812 // Using APA102, WS2812, WS2801. Don’t forget to change LEDS.addLeds.
#define NUM_LEDS 80 // Number of LED’s.
// Global variables can be changed on the fly.
uint8_t max_bright = 84; // 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 = 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(3000); // Power-up safety delay.
Serial.begin(57600); // Initialize serial port for debugging.
// 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.
} // setup()
void loop () {
ChangeMe(); // Check the demo loop for changes to the variables.
twinkle();
mover();
EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence.
twinkle();
mover();
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.
if (randhue) thishue = random16(0,255); // Randomize every LED if TRUE
if (i < NUM_LEDS) leds[i] = CHSV(thishue, thissat, thisbri); // Only the lowest probability twinkles will do. You could even randomize the hue/saturation.
for (int j = 0; j < NUM_LEDS; j++) leds[j].fadeToBlackBy(thisfade); // Use the FastLED fade method.
} // twinkle()
void mover() {
static uint8_t hue = 0;
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] += CHSV(hue, 255, 255);
leds[(i+5) % NUM_LEDS] += CHSV(hue+85, 255, 255); // We use modulus so that the location is between 0 and NUM_LEDS
leds[(i+10) % NUM_LEDS] += CHSV(hue+170, 255, 255); // Same here.
show_at_max_brightness_for_power();
fadeToBlackBy(leds, NUM_LEDS, thisfade); // Low values = slower fade.
delay(thisdelay); // UGH!!! A blocking delay. If you want to add controls, they may not work reliably.
}
} // mover()
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; thisfade=240; break; // You can change values here, one at a time , or altogether.
case 5: thisdelay=50; thisfade=128; break;
case 10: thisdelay=100; thisfade=64; break; // Only gets called once, and not continuously for the next several seconds. Therefore, no rainbows.
case 15: break;
}
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()
I found an example for you @Freddie_Olivas . Let it run for a bit and see how it changes. You can set DEBUG=1 to have some info printed to the serial monitor.
Way cool Mark. This is exactly what I was looking for. I’m blown away!
Thank you very much.
You’re welcome. Let me know if you have any questions on how it works.
I’m still giving it some thought. I’ve played around with it a bit and munged it up some.
But it’s not broken. I was wondering: What would I state to have a 2LED chase or 3LED chase? One LED looks cool but there are other ideas I have and I love to experiment with code to see what happens. I got it to do one LED on opposite sides of a shape and they chase around. Looks cool.
Here’s another version (v3) that allows you to double, triple up, etc., the number of pixels in the chase. New variable is called “width”. (If you make it too wide of course it can just fill in the strip completely so there aren’t any black/off pixels any more.)
There’s also another variable, “hue2_shift”, to allow a secondary color when width is more then 1. Set to 0 if you don’t want a secondary color.
Okay I’m using my tablet because I can’t find the site where we left off.
Yes I do have a question:
Your code:
EVERY_N_SECONDS(120)€
spacing = spacing+ 1;
If (spacing == 11) (spacing = 2;) // don’t want to go past 10
If (spacing == 6) (spacing=8;) // want to skip 6 & 7 as they don’t look right
If (spacing == 9) (spacing = 10;) // skip 9, go-to 10, do 10 then start again at 2
What is happening is the code gets stuck at the last change and never goes back to the beginning. If I skip the second and third line the sketch runs through all 10 sequences including steps 6,7 and 9. Is there a way to jump past some sequences without getting stuck?
Thanks Marc.
Just found the proper site now I can write. Marc Miller can you help me out?
@Freddie_Olivas It seems to work as you typed it above (after fixing “if” statement formatting). From a quick test:
http://pastebin.com/qHEvivjL
[ Adding a temporary Serial.print statement into your code is a great way to see how variables are changing. I use them all the time to confirm what’s happening, or more often when something’s not happening as expect. Comment them out or delete them when done as they do slow things down just a bit. ]
Got it and now works as expected. Thank you very much. Now I will play with the version 3 you recently posted. Yippee.
I like this code but I’m trying to incorporate it into the Demo Reel sketch and I’m having problems. I basically made a function out of the lines that were within the main loop but now the lights flicker really rapidly. I think it has to do with the EVERY_N_MILLISECONDS(holdTime) being in the function and that function being called repeatedly. But, I’m not sure how to fix it.
Here’s my code: https://pastebin.com/8jeKFQiq
It’s ok to use EVERY_N in a function. For example, here’s a version of DemoReel with several functions that use EVERY_N.
Double check that you’re not trying to write data to a led outside of your pixel range.