Page 1 of 1

Arduino – LEDStrip effects for NeoPixel and FastLED

Arduino – LEDStrip effects for NeoPixel and FastLED
   1077

For those who have read the article “Arduino – Controlling a WS2812 LED strand with NeoPixel or FastLED” might have gotten infected by urge to get more effects, after all … some of these LEDStrip effects look pretty slick!

With the holiday coming up real soon, I figured this would be a great opportunity to create and post some cool effects for your LED strips. Maybe you can be your own Griswold (National Lampoon’s Christmas Vacation) with these! 

You’ve got to check out the Fire effect with toilet paper – looks pretty cool!

Please read the article Arduino – Controlling a WS2812 LED first, as it will show you some of the basics.
Also note that you’re invited to post your own effects or ideas in the comment section or in the Arduino/WS2811/WS2812 – Share you lighting effects and patterns here … forum topic.




LEDEffects

Below an overview of this article.

All these effects work with NeoPixel and FastLED, and with each effect I made a little demo video.

UPDATE – All effects in one sketch 

Bij popular demand, I’ve written an article how all these effects can be placed in one sketch, allowing you to toggle effects.
Read more about it in this article: Arduino – All LED effects in one Sketch. (updated the link)

 

Overview

Preparing your Arduino and your LED strip

Please keep in mind that these effects are here for you to play with and hopefully invite you to create your own cool effects … 

For your convenience, you can download all sources here as well:

Download - LEDEeffects Sources 

Filename:  LEDEeffects-Sources.zip
Platform:  Undefined
Version:  1.0
File size:  34.5 kB
Date:  2015-11-08
 Download Now  Send me a cup of Coffee    

These examples rely on the following setup (as described in the Controlling a WS2812 LED with an Arduino article).
Please read carefully.

Arduino IDE and Library versions 

For this article I have used the Arduino IDE 1.6.6, which (after you installed either FastLED or NeoPixel) will show a message to update either of these (and possibly others) libraries. Please do so.

Arduino Connected to PC

The following I use for when the Arduino is connected to my PC:

Arduino & WS2812 - USB and External Power

Arduino & WS2812 – USB and External Power

Arduino Standalone

After you’ve uploaded your variation of effects into the Arduino, and you’d like it to run standalone, then this setup is what you need. Without a connection to your computer, the Arduino will need +5V from the external power supply.

 This is for stand-alone ONLY so when the Arduino is NOT connect to a PC!

Arduino & WS2812 - Only running on external power supply

Arduino & WS2812 – Only running on external power supply

 

 

Helpful tool: Color Picker

This tool might be helpful when picking colors:
LED colors are build up out of 3 numbers: red, green and blue (RGB).
Each number is a byte so it each has a range of 256 values (Decimal: 0 … 255, Hexadecimal: 00 … FF).

Now the human brain (usually) doesn’t work with RGB numbers, so I’ve added this little tool to pick colors.
You can select the color and it should give you the hexadecimal value of the selected color.
Please note that the LED colors might be slightly off – after all they are not calibrated.


Color picker:

Usage:
Click the input box and a popup will show a color picker. Choose your color, and the hexadecimal value will appear.
To use this in your Arduino Sketch:

The first 2 characters represent RED,
the second set of two characters is for GREEN and
the last 2 characters represent BLUE.

Add ‘0x‘ in front of each of these hex values when using them (‘0x’ designates a hexadecimal value).

Example:
This purple is B700FE.
The hexadecimal values: red is B7, green is 00 and blue is FE.

As the Arduino can work straight away with hexadecimal number, you will need to type “0x” in front of it – so it can see the difference between regular decimal number and these hexadecimal numbers.
So for example a NeoPixel strip.Color() call would look something like this:

strip.Color( 0xB7, 0x00, 0xFE );

 

Make your effects cooler: Diffuse Light (toilet paper magic)

I love playing with these LED strips, but sometimes they feel a little too … I don’t know how to say it.
With some effects you’d prefer to not see the individual LEDs light up.

To remedy that without too much effort, you can diffuse the light – make it more fuzzy.

There are different techniques for that, anywhere from using ping-pong balls (which works great for one or two LEDs), frosted glass (tube light!) or plastic tubes, cloth sheets etc.

I had none of these available – I used to have ping ping balls but my dog decided it to be awesome for chasing and chewing. So I’m out of those.

To my surprise, regular toilet paper (yes!) actually does a pretty good job with the diffusing as well. Naturally, I had only “fancy” toilet paper with a print on it, and neutral toilet paper would have looked even better, but you get the idea when you se these two examples.

Just make sure to keep the toilet paper roughly an inch (2 to 3 centimeter) above the LEDs – don’t let the LEDs touch the toilet paper.

Note: Both examples look better when held vertical, but without much assistance in my house, I had to do it horizontally.

The Fire Effect is my favorite and shows best in a darker environment, but look at what the toilet paper is doing … I love it!

The Red, White and Blue bouncing balls look a lot more interesting when diffused as well.

 

Required Library – NeoPixel or FastLED ?

Since both are pretty good, but are not used in the same way – ie. they are not drop-in replacements for each other. That’s why I decided to create a few “generic” functions so that the “effect” function here can be generic as well, so these functions work with either of these 2 libraries.

Either library can be used! 

First make sure either NeoPixel or FastLED is installed. To install one (or both) of these desired library, I refer you to the article “Arduino – Controlling a WS2812 LED strand with NeoPixel or FastLED“.

 Note : FastLED seems slightly faster. In the tests I’ve run I would estimate that FastLED is about 15% faster than NeoPixel. You will notice this with large amounts of LEDs (as I experienced with 300+ LEDs). On the other hand, NeoPixel seems to take less memory on your Arduino. Also note that the functions in FastLED are far superior to NeoPixel.

Now I wrote tiny wrappers around some of the basic functions of NeoPixel and FastLED – and I’m sure there is room for improvement. Suggestions are welcome.

Basic framework

For each of the LEDStrip effects, we will use a basic framework of code which we reuse in each of the effects.
It is important that you pay attention to these since the basic settings for your strip is being done there.

Now in this framework I’ve also defined 3 generic functions.
These functions will automatically grab the code needed for the library you’re using (when compiling).

showStrip();

This function simply applies the recent changes to pixel colors and makes them visible.
It calls strip.show (NeoPixel) or FastLED.show (FastLED).

setPixel(Pixel, red, green, blue);

With this function we set the color of an individual pixel (LED).
You will need to pass the pixel number (start counting at zero) and the RGB values.
For NeoPixel it will call setPixelColor, and for FastLED it will assign values to the leds array.

setAll(red, green, blue);

This function sets the entire strip to a give color. You can use it to set the entire strip to a given color or for example with setAll(0,0,0) to black (off).

The code we present, with each of the effects, is simple replacing this part of the code in the framework code:


1
2
3
4
5
6
7
// *** REPLACE FROM HERE ***
void loop() {
  // ---> here we call the effect function <---
}

// ---> here we define the effect function <---
// *** REPLACE TO HERE ***

So in our effects code examples you will only see the loop() section and the effect function.
Settings and the 3 wrapper functions will not be displayed, but are most certainly needed!

FastLED Framework

This is the basic code for use with the FastLED library.

Here we include the needed library (line 1), define the number of LEDs (line 2), define the Arduino pin used (line 4), and define some strip specific settings (line 8) like color order (RGB, GRB etc.).


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "FastLED.h"
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
#define PIN 6

void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

// *** REPLACE FROM HERE ***
void loop() {
  // ---> here we call the effect function <---
}

// ---> here we define the effect function <---
// *** REPLACE TO HERE ***

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

 

NeoPixel Framework

For NeoPixel we use a similar framework for each of the effects.

Line 1 includes the NeoPixel library, line 2 defines the used Arduino pin (6), the comment lines explain a little about the parameters used in line 10, and in line 10 we define strip specifics.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 60
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

// *** REPLACE FROM HERE ***
void loop() {
 // ---> here we call the effect function <---
}

// ---> here we define the effect function <---
// *** REPLACE TO HERE ***

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

 

LEDStrip Effect – Fade In and Fade Out: Red, Green and Blue

With this effect, we use fixed colors for all LEDs, in sequence: Red, Green and Blue.
We will slowly increase brightness and when the maximum brightness has been reached, we will start decreasing the brightness again until the LEDs are OFF.

Since the function is in the loop(), it will keep repeating itself.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void loop() {
  RGBLoop();
}

void RGBLoop(){
  for(int j = 0; j < 3; j++ ) {
    // Fade IN
    for(int k = 0; k < 256; k++) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
    // Fade OUT
    for(int k = 255; k >= 0; k--) {
      switch(j) {
        case 0: setAll(k,0,0); break;
        case 1: setAll(0,k,0); break;
        case 2: setAll(0,0,k); break;
      }
      showStrip();
      delay(3);
    }
  }
}

 

LEDStrip Effect – Fade In and Fade Out Your own Color(s)

Now fading in and out only red, green and blue is nice, but what about fade in and out your own color?

If you’re not sure how to determine your own color, check out the previously mentioned Color Picker.

As with all of these effects, you can mix and match whatever you like. But if you’re in a patriotic mood, then there is not much better than our belowed red, white and blue. You can accomplish that by calling the function for each individual color. So, for example, by replacing the loop() with the following:


1
2
3
4
5
6
7
8
9
...

void loop() {
  FadeInOut(0xff, 0x00, 0x00); // red
  FadeInOut(0xff, 0xff, 0xff); // white
  FadeInOut(0x00, 0x00, 0xff); // blue
}

...

The effect code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void loop() {
  FadeInOut(0xff, 0x77, 0x00);
}

void FadeInOut(byte red, byte green, byte blue){
  float r, g, b;
     
  for(int k = 0; k < 256; k=k+1) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
  }
     
  for(int k = 255; k >= 0; k=k-2) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
  }
}

 

LEDStrip Effect – Strobe

Now, this effect quickly flashes all LEDs a number of time and then pause a certain time after that.

I made this one more configurable, so you determine how much time should be paused between flashes, and how much the “end pause” should last.

The function takes 6 parameters.

The first 3 are the same red, green and blue we have seen in the previous effect so you can define your own color – see the Color Picker above for picking a color. In the example I used White.

The next parameter (StrobeCount) indicates how many flashes you’d like to see.
Parameters 5 (FlashDelay) and 6 (EndPause) are for delays between each individual flash and how long the function should wait once it completed all flashes.

  Be careful with the strobe effect – it may cause epileptic seizures!

Effect code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void loop() {
  // Slower:
  // Strobe(0xff, 0x77, 0x00, 10, 100, 1000);
  // Fast:
  Strobe(0xff, 0xff, 0xff, 10, 50, 1000);
}

void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip();
    delay(FlashDelay);
  }
 
 delay(EndPause);
}

 

LEDStrip Effect – Blinking Halloween Eyes

Well, this one is for those amongst us who like a good Halloween decoration – it shows two red eyes at a random spot on the strip that fade away.

I created this function to be somewhat flexible, and as you can see in the example code, I did use the random function a bit to make it more suitable for a Halloween setup.

Anyhow, theHalloweenEyes() function takes quite a few parameters.

Again I’ve used the option to pass your preferred color by passing Red, Green and Blue (see also: Color Picker).
Usually one would probably pick red as the eye color (0xff, 0x00, 0x00).

HalloweenEyes Parameters
 Parameter  Purpose  Examples
 red  Red Color  0xFF
 green  Green Color  0x00
 blue  Blue Color  0x00
 EyeWidth  How many LEDs per eye  1
 EyeSpace  Number of LEDs between the eyes  2
 Fade  Fade out or not  true
false
 Steps  Number of steps on fade out  10
 FadeDelay  Delay between each fade out level  100
 EndPause  Delay after everything is completed  1000

As you can see in the code as straight forward call would be:

HalloweenEyes(0xff, 0x00, 0x00, 1,4, true, 10, 80, 3000);

But a more advanced call could make things more alive and interesting:


1
2
3
4
HalloweenEyes(0xff, 0x00, 0x00,
              1, 4,
              true, random(5,50), random(50,150),
              random(1000, 10000));

In the more advanced call example, we make the fade out steps and fade out delays a little random. So some eyes disappear faster than others. And the “EndPause” delays has been made random as well, so that in the end eyes will appear more random.

Using Random numbers … 

The Arduino random(Min,Max) function returns a random number between “Min” and “Max”.

Calling the randomSeed() function just makes things a little bit better more random.

You can use the calls to random() in the parameter of the functions presented here. You’ll see me do this occasionally to give the effect a more fun appearance.

Something to play with 

The effect code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
void loop() {
  // Fixed:
  // HalloweenEyes(0xff, 0x00, 0x00, 1,4, true, 10, 80, 3000);
  // or Random:
  HalloweenEyes(0xff, 0x00, 0x00,
                1, 4,
                true, random(5,50), random(50,150),
                random(1000, 10000));
}

void HalloweenEyes(byte red, byte green, byte blue,
                   int EyeWidth, int EyeSpace,
                   boolean Fade, int Steps, int FadeDelay,
                   int EndPause){
  randomSeed(analogRead(0));
 
  int i;
  int StartPoint  = random( 0, NUM_LEDS - (2*EyeWidth) - EyeSpace );
  int Start2ndEye = StartPoint + EyeWidth + EyeSpace;
 
  for(i = 0; i < EyeWidth; i++) {
    setPixel(StartPoint + i, red, green, blue);
    setPixel(Start2ndEye + i, red, green, blue);
  }
 
  showStrip();
 
  if(Fade==true) {
    float r, g, b;
 
    for(int j = Steps; j >= 0; j--) {
      r = j*(red/Steps);
      g = j*(green/Steps);
      b = j*(blue/Steps);
     
      for(i = 0; i < EyeWidth; i++) {
        setPixel(StartPoint + i, r, g, b);
        setPixel(Start2ndEye + i, r, g, b);
      }
     
      showStrip();
      delay(FadeDelay);
    }
  }
 
  setAll(0,0,0); // Set all black
 
  delay(EndPause);
}

 

LEDStrip Effect – Cylon

I suppose not all of us know what a Cylon is, but I grew up with those cool robots and I for sure wanted to have one.
My familiar with Knight Rider (although that’s about the same era)? It’s kind-a similar.

This type of “scanner” is often referred to as a Larson scanner is named after Glen Larson, the man responsible for producing both the original Battlestar Galactica and Knight Rider television shows.

Anyhow, here an effect that simulates the moving “eye” of a Cylon: A red “eye” moves from left to right and back, over and over again. Kind-a ike a bouncy ball haha.

The Cylon() function takes 6 parameters, where the first 3 are you preferred color (a Cylon has a red “eye”, but you can pick whatever you like with the Color Picker). The 4th parameter (EyeSize) determines how many LEDs run around, or: the width of the “eye” (outer 2, faded, LEDs not counted).

The 5th parameter (SpeedDelay) influences how fast the eye moves, higher values means slow movement.
The last parameter (ReturnDelay) sets how much time it should wait to bounce back.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void loop() {
  CylonBounce(0xff, 0, 0, 4, 10, 50);
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){

  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
 
  delay(ReturnDelay);
}

 

LEDStrip Effect – The new KITT

I mentioned KITT already in the previous effect, and KITT did make a rather miserable comeback (see also this KITT-duino Instructables article).

In this comeback the KITT scanner started behaving differently. Instead of bouncing back and forth it now follows this pattern:

New Larson Scanner (KITT) directions

New Larson Scanner (KITT) directions

I had no clue about the change – I guess the revived show didn’t make that much of an impression – so I did get this pattern from the earlier mentioned KITT-duino Instructable.

As you can see, all steps repeat so I decided to make separate functions for the repeating patterns.
All these functions take the same parameters – so you can use them individually as well.

Obviously first the color definition (red, green and blue), then the size of the “moving eye”, the speed delay and how long we’d like to wait when the LEDs bounce.

NewKITT() calls for the complete routine of earlier mentioned pattern, where as CenterToOutside()OutsideToCenter()LeftToRight() and RightToLeft() do their fraction of the pattern. Again: they can be used on their own, so feel free to mix and match.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
void loop() {
  NewKITT(0xff, 0, 0, 8, 10, 50);
}

void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
}

void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
    setAll(0,0,0);
   
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
   
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
   
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
    setAll(0,0,0);
   
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
   
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
   
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

 

LEDStrip Effect – Twinkle

This effect will blink one or more LEDs in a given color.
The function takes the usual color parameters, which you can determine with the Color Picker.

The 4th parameter (Count) determines how many pixels will be done in one run, where as the 5th parameter determines how much time will be paused between individual pixels (speed).

The 6th parameter (OnlyOne) should be true if you want to see only one LED at a time.
If it’s set to false then all “Count” number of LEDs will be visible (added one at a time).


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void loop() {
  Twinkle(0xff, 0, 0, 10, 100, false);
}

void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);
 
  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),red,green,blue);
     showStrip();
     delay(SpeedDelay);
     if(OnlyOne) {
       setAll(0,0,0);
     }
   }
 
  delay(SpeedDelay);
}

 

LEDStrip Effect – Random Color Twinkle

This is a variation on the Twinkle() effect.
The only difference is that the colors are now randomly generated, and therefor the first 3 color parameters are no longer of use and have been removed.

So we use only 3 parameters:

The first parameter (Count) determines how many pixels will be done in one run, where as the second parameter determines how much time will be paused between individual pixels (speed).

The last parameter (OnlyOne) should be true if you want to see only one LED at a time.
If it’s set to false then all “Count” number of LEDs will be visible (added one at a time).


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void loop() {
  TwinkleRandom(20, 100, false);
}

void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
  setAll(0,0,0);
 
  for (int i=0; i<Count; i++) {
     setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
     showStrip();
     delay(SpeedDelay);
     if(OnlyOne) {
       setAll(0,0,0);
     }
   }
 
  delay(SpeedDelay);
}

 

LEDStrip Effect – Sparkle

With this one, a variation of Twinkle, I had Christmas in mind.

The function only lights up one LED and switches it off right after that.
When placed in the loop() it will continuously do that.

Again the usual parameters: Color and SpeedDelay.

If you’d prefer random colors, then you can could Sparkle as such:


Sparkle(random(255), random(255), random(255), 0);

The effect code, with white as the selected color:


1
2
3
4
5
6
7
8
9
10
11
void loop() {
  Sparkle(0xff, 0xff, 0xff, 0);
}

void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

 

LEDStrip Effect – Snow Sparkle

This variant of Sparkle is intended to look like snow with to occasional sparkle.

Having snow in mind, the first 3 parameters (the background color) should be a more dim white and that’s why I choose 10 10 10 – but feel free to pick your own color.

The 4th parameter, SparkleDelay, indicates how long a “sparkle” will be visible. Do not set it too short, otherwise you’d barely notice anything happening.

The last parameter indicates how much time should be waited after a sparkle has been made visible and has been removed.

You could use a fixed interval for that:


SnowSparkle(0x10, 0x10, 0x10, 20, 200);

I like it better though when it’s more random. For that I’ve added the random function again to the function call where (in this example) the wait time between sparkles is a random number between 100 and 1000 milliseconds (1/10th of a second and a full second).


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void loop() {
  SnowSparkle(0x10, 0x10, 0x10, 20, random(100,1000));
}

void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
  setAll(red,green,blue);
 
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,0xff,0xff,0xff);
  showStrip();
  delay(SparkleDelay);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
}

 

LEDStrip Effect – Running Lights

This effect makes multiple groups of LEDs chase each other. Kind-a like the running lights you’d use to see in stores during the holidays.

It takes 4 parameters, of which the first 3 define the color (roughly).
The last parameter indicates how much delay is put in the loop, the higher the number, the slower it will go.

You could of course play with the colors, for example on a theme night:


1
2
3
4
5
void loop() {
  RunningLights(0xff,0,0, 50);        // red
  RunningLights(0xff,0xff,0xff, 50);  // white
  RunningLights(0,0,0xff, 50);        // blue
}

The effect:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void loop() {
  RunningLights(0xff,0xff,0x00, 50);
}

void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
  int Position=0;
 
  for(int j=0; j<NUM_LEDS*2; j++)
  {
      Position++; // = 0; //Position + Rate;
      for(int i=0; i<NUM_LEDS; i++) {
        // sine wave, 3 offset waves make a rainbow!
        //float level = sin(i+Position) * 127 + 128;
        //setPixel(i,level,0,0);
        //float level = sin(i+Position) * 127 + 128;
        setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                   ((sin(i+Position) * 127 + 128)/255)*green,
                   ((sin(i+Position) * 127 + 128)/255)*blue);
      }
     
      showStrip();
      delay(WaveDelay);
  }
}

 

LEDStrip Effect – Color Wipe

I took this one from the NeoPixel library. It sets one LED after the other to a give color. The result being a full strip in a given color if you’d run it only once.

In the example below I actually call this function twice, the first one to set all LEDs to green and the second on to set each LED to black (OFF), so we get a chaser like effect.

The function parameters are simple; the usual color parameters (see color picker), and a delay time (the higher this number, the slower it will go).


1
2
3
4
5
6
7
8
9
10
11
12
void loop() {
  colorWipe(0x00,0xff,0x00, 50);
  colorWipe(0x00,0x00,0x00, 50);
}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
  for(uint16_t i=0; i<NUM_LEDS; i++) {
      setPixel(i, red, green, blue);
      showStrip();
      delay(SpeedDelay);
  }
}

 

LEDStrip Effect – Rainbow Cycle

Again one I took from the NeoPixel library.
This function cycles rainbow colors, where the only parameter is the speed delay.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
void loop() {
  rainbowCycle(20);
}

void rainbowCycle(int SpeedDelay) {
  byte *c;
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< NUM_LEDS; i++) {
      c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
      setPixel(i, *c, *(c+1), *(c+2));
    }
    showStrip();
    delay(SpeedDelay);
  }
}

byte * Wheel(byte WheelPos) {
  static byte c[3];
 
  if(WheelPos < 85) {
   c[0]=WheelPos * 3;
   c[1]=255 - WheelPos * 3;
   c[2]=0;
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   c[0]=255 - WheelPos * 3;
   c[1]=0;
   c[2]=WheelPos * 3;
  } else {
   WheelPos -= 170;
   c[0]=0;
   c[1]=WheelPos * 3;
   c[2]=255 - WheelPos * 3;
  }

  return c;
}

 

LEDStrip Effect – Theatre Chase

Another one converted from the NeoPixel library.
With this effect LEDs are chasing each other like what you’d see in an old Theatre.
Parameters are again color and speed delay.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void loop() {
  theaterChase(0xff,0,0,50);
}

void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < NUM_LEDS; i=i+3) {
        setPixel(i+q, red, green, blue);    //turn every third pixel on
      }
      showStrip();
     
      delay(SpeedDelay);
     
      for (int i=0; i < NUM_LEDS; i=i+3) {
        setPixel(i+q, 0,0,0);        //turn every third pixel off
      }
    }
  }
}

 

LEDStrip Effect – Theatre Chase Rainbow

Another one from NeoPixel, which combines Rainbow and TheatreChase.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
void loop() {
  theaterChaseRainbow(50);
}

void theaterChaseRainbow(int SpeedDelay) {
  byte *c;
 
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < NUM_LEDS; i=i+3) {
          c = Wheel( (i+j) % 255);
          setPixel(i+q, *c, *(c+1), *(c+2));    //turn every third pixel on
        }
        showStrip();
       
        delay(SpeedDelay);
       
        for (int i=0; i < NUM_LEDS; i=i+3) {
          setPixel(i+q, 0,0,0);        //turn every third pixel off
        }
    }
  }
}

byte * Wheel(byte WheelPos) {
  static byte c[3];
 
  if(WheelPos < 85) {
   c[0]=WheelPos * 3;
   c[1]=255 - WheelPos * 3;
   c[2]=0;
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   c[0]=255 - WheelPos * 3;
   c[1]=0;
   c[2]=WheelPos * 3;
  } else {
   WheelPos -= 170;
   c[0]=0;
   c[1]=WheelPos * 3;
   c[2]=255 - WheelPos * 3;
  }

  return c;
}

 

LEDStrip Effect – Fire

This effect looks best when hanging your LED strip vertical and it simulates a one LED wide “fire”, and is adapted from an example in FastLED, which is adapted from work done by Mark Kriegsman (called “Fire2012”).

Note that this effect looks awesome when using diffuse light!

This function takes 3 parameters.

The first one (Cooling) indicates how fast a flame cools down. More cooling means shorter flames, and the recommended values are between 20 and 100. 50 seems the nicest.

The Second parameter (Sparking), indicates the chance (out of 255) that a spark will ignite. A higher value makes the fire more active. Suggested values lay between 50 and 200, with my personal preference being 120.

The last parameter (SpeedDelay) allows you to slow down the fire activity … a higher value makes the flame appear slower.
You’ll have to play a little with that, but personally I like a value between 0 and 20.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
void loop() {
  Fire(55,120,15);
}

void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[NUM_LEDS];
  int cooldown;
 
  // Step 1.  Cool down every cell a little
  for( int i = 0; i < NUM_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);
   
    if(cooldown>heat[i]) {
      heat[i]=0;
    } else {
      heat[i]=heat[i]-cooldown;
    }
  }
 
  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for( int k= NUM_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
  }
   
  // Step 3.  Randomly ignite new 'sparks' near the bottom
  if( random(255) < Sparking ) {
    int y = random(7);
    heat[y] = heat[y] + random(160,255);
    //heat[y] = random(160,255);
  }

  // Step 4.  Convert heat to LED colors
  for( int j = 0; j < NUM_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
  }

  showStrip();
  delay(SpeedDelay);
}

void setPixelHeatColor (int Pixel, byte temperature) {
  // Scale 'heat' down from 0-255 to 0-191
  byte t192 = round((temperature/255.0)*191);
 
  // calculate ramp up from
  byte heatramp = t192 & 0x3F; // 0..63
  heatramp <<= 2; // scale up to 0..252
 
  // figure out which third of the spectrum we're in:
  if( t192 > 0x80) {                     // hottest
    setPixel(Pixel, 255, 255, heatramp);
  } else if( t192 > 0x40 ) {             // middle
    setPixel(Pixel, 255, heatramp, 0);
  } else {                               // coolest
    setPixel(Pixel, heatramp, 0, 0);
  }
}

 

LEDStrip Effect – Bouncing Balls

This effect looks best with the LEDstrip vertical, and shows one or more bouncing balls in a given color.
This effect is an adapted version of bouncing balls by Danny Wilson.

The parameters are as usual the color of (all) the balls, and the last parameter is the number of balls you’d like to see bounce.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
void loop() {
  BouncingBalls(0xff,0,0, 3);
}

void BouncingBalls(byte red, byte green, byte blue, int BallCount) {
  float Gravity = -9.81;
  int StartHeight = 1;
 
  float Height[BallCount];
  float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
  float ImpactVelocity[BallCount];
  float TimeSinceLastBounce[BallCount];
  int   Position[BallCount];
  long  ClockTimeSinceLastBounce[BallCount];
  float Dampening[BallCount];
 
  for (int i = 0 ; i < BallCount ; i++) {  
    ClockTimeSinceLastBounce[i] = millis();
    Height[i] = StartHeight;
    Position[i] = 0;
    ImpactVelocity[i] = ImpactVelocityStart;
    TimeSinceLastBounce[i] = 0;
    Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
  }

  while (true) {
    for (int i = 0 ; i < BallCount ; i++) {
      TimeSinceLastBounce[i] =  millis() - ClockTimeSinceLastBounce[i];
      Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
 
      if ( Height[i] < 0 ) {                      
        Height[i] = 0;
        ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
        ClockTimeSinceLastBounce[i] = millis();
 
        if ( ImpactVelocity[i] < 0.01 ) {
          ImpactVelocity[i] = ImpactVelocityStart;
        }
      }
      Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
    }
 
    for (int i = 0 ; i < BallCount ; i++) {
      setPixel(Position[i],red,green,blue);
    }
   
    showStrip();
    setAll(0,0,0);
  }
}

 

LEDStrip Effect – Multi Color Bouncing Balls

This is a more complex variant of the Bouncing Balls effect.
Instead of just one color, it allows the use of multiple colors, each defined by you.

This makes the function call a little bit more complex, since I wanted it to work for any number of balls you’d like set. The problem would be how to pass the color for each ball.

To accomplish this you will have to define a so called multi dimensional array – which may sound scary, but I’ll walk you through that.

Let’s first look at the effect itself.

The function BouncingColoredBalls() takes only two parameters. The number of balls and that scary array of colors. Easy so far, right?

Now, let’s say we want to use 3 balls and use a red, white and blue ball. So 3 balls, requires 3 colors.


1
2
3
byte colors[3][3] = { {0xff, 0,0},
                      {0xff, 0xff, 0xff},
                      {0, 0, 0xff} };

The first line defines the variable “colors” as a 3 x 3 array of bytes: byte colors[3][3] (downside: you can only use up to 255 balls)
We want 3 balls, so we need 3 sets of 3 values to define their colors. So the first “3” indicates the number of Balls.
Remember the Color Picker? Each color has 3 values: red, green and blue. So the second “3” indicates the 3 colors for each ball.

I guess I didn’t think that one through … argh … oh well I’ll show you some examples with a different number of balls.

We’d like to assign these values right away and in C we have a specific notation for that. For a regular array we use { value1, value2, ... valuen } …. so for 3 values this could be { 1, 2, 3 } , enclosed with accolades ( { and } ) .

Since we have a multi dimensional array – an array that has arrays as values – we will need to pass the arrays (colors) as values, so for a 3 balls and 3 colors array we need to do something like this: { { value1, value2, value2 }, { value1, value2, value2 }, { value1, value2, value2 } } .

See the pattern? { value1, value2, value2 } is a set of 3 values (bytes) for one color.

Here an example if we would use only 2 balls, say for Christmas we use red and green balls:


1
2
byte colors[2][3] = { {0xff, 0, 0},  
                      {0, 0xdd, 0} };

2 Balls, each having a red, green and blue value (3).

Now to make this work we have to make 100% sure that the first number (2 in the 2 ball example) of the array matches with the first parameter we pass to the function. So the 2 ball Christmas example would be called as such:


1
2
3
4
5
6
void loop() {
  byte colors[2][3] = { {0xff, 0,0},
                        {0, 0xff, 0} };

  BouncingBalls(2, colors);
}

I know these can be a little out there to grasp, I hope I did explain this right …

Just another example, with 5 balls (red, green, blue, white and yellow), to illustrate the usage of the array:


1
2
3
4
5
6
7
8
9
void loop() {
  byte colors[5][3] = { {0xff, 0,0},       // red
                        {0, 0xff, 0},      // green
                        {0, 0, 0xff},      // blue
                        {0xff, 0xff, 0xff},// white
                        {0xff, 0xff, 0} }; // yellow

  BouncingBalls(5, colors);
}

OK, now that we understand that part, here the effect code, for the red, white and blue Bouncing Balls effect:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
void loop() {
  byte colors[3][3] = { {0xff, 0,0},
                        {0xff, 0xff, 0xff},
                        {0   , 0   , 0xff} };

  BouncingColoredBalls(3, colors);
}

void BouncingColoredBalls(int BallCount, byte colors[][3]) {
  float Gravity = -9.81;
  int StartHeight = 1;
 
  float Height[BallCount];
  float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
  float ImpactVelocity[BallCount];
  float TimeSinceLastBounce[BallCount];
  int   Position[BallCount];
  long  ClockTimeSinceLastBounce[BallCount];
  float Dampening[BallCount];
 
  for (int i = 0 ; i < BallCount ; i++) {  
    ClockTimeSinceLastBounce[i] = millis();
    Height[i] = StartHeight;
    Position[i] = 0;
    ImpactVelocity[i] = ImpactVelocityStart;
    TimeSinceLastBounce[i] = 0;
    Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
  }

  while (true) {
    for (int i = 0 ; i < BallCount ; i++) {
      TimeSinceLastBounce[i] =  millis() - ClockTimeSinceLastBounce[i];
      Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
 
      if ( Height[i] < 0 ) {                      
        Height[i] = 0;
        ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
        ClockTimeSinceLastBounce[i] = millis();
 
        if ( ImpactVelocity[i] < 0.01 ) {
          ImpactVelocity[i] = ImpactVelocityStart;
        }
      }
      Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
    }
 
    for (int i = 0 ; i < BallCount ; i++) {
      setPixel(Position[i],colors[i][0],colors[i][1],colors[i][2]);
    }
   
    showStrip();
    setAll(0,0,0);
  }
}

 

LEDStrip Effect – Meteor Rain

This effect, based on a request by Hendrik, has been added almost 2 years (Januari 1st 2018) after writing this article – the video could have been done better and this effect should be vertical. None the less … here it is. This effect came with it’s own challenge since FastLED has a great function for dimming LEDs, NeoPixel however does not.

 

As you can see, it’s a kind of meteor falling from the sky.

An example of how to call this meteor effect:


meteorRain(0xff,0xff,0xff,10, 64, true, 30);

As with some of the previous examples, you can use the red, green and blue parameters to set the color of your meteor – you can use the Color Picker to find a color (even though it’s not perfect – it will get you in the right direction).

After the color, we can set the meteor size – the number of LEDs that represent the meteor, not counting the tail of the meteor.

The 5th parameter sets how fast the meteor tail decays/ disappears. A larger number makes the tail short and/or disappear faster. Theoretically a value of 64 should reduce the brightness by 25% for each time the meteor gets drawn.

Since meteors are not perfect, I’ve added the 6th parameter to mimic some sorts of difference in debris by making the decay a little random. If this value is set to “true” then some randomness is added to the rail. If you set the value to “false” then the tail will be very smooth.

Finally there is the last parameter, which basically indicates how much the drawing speed has to be delayed. A value of zero (0) means maximum speed. Any value above zero indicates how many milliseconds (1000 milliseconds in a second) the drawing will be delayed.

The effect code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
void loop() {
  meteorRain(0xff,0xff,0xff,10, 64, true, 30);
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);
 
  for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
   
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}

void fadeToBlack(int ledNo, byte fadeValue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
    // NeoPixel
    uint32_t oldColor;
    uint8_t r, g, b;
    int value;
   
    oldColor = strip.getPixelColor(ledNo);
    r = (oldColor & 0x00ff0000UL) >> 16;
    g = (oldColor & 0x0000ff00UL) >> 8;
    b = (oldColor & 0x000000ffUL);

    r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
    g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
    b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
   
    strip.setPixelColor(ledNo, r,g,b);
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[ledNo].fadeToBlackBy( fadeValue );
 #endif  
}

 

Support Us ...


Your support is very much appreciated, and can be as easy as sharing a link to my website with others, or on social media.

Support can also be done by sponsoring me, and even that can be free (e.g. shop at Amazon).
Any funds received from your support will be used for web-hosting expenses, project hardware and software, coffee, etc.

Thank you very much for those that have shown support already!
It's truly amazing to see that folks like my articles and small applications.

Please note that clicking affiliate links, like the ones from Amazon, may result in a small commission for us - which we highly appreciate as well.

Comments


There are 1077 comments. You can read them below.
You can post your own comments by using the form below, or reply to existing comments by using the "Reply" button.

  • Dec 1, 2015 - 8:38 PM - Michael Comment Link

    Great tutorial!  Thanks so much for sharing the examples and creating the videos!

    Reply

    Michael

    • Dec 2, 2015 - 8:19 AM - hans - Author: Comment Link

      Thanks Michael for taking the time to post a “Thank you” note! It’s very much appreciated! 

      Reply

      hans

    • Dec 21, 2016 - 12:55 PM - seaworld Comment Link

      It’s nice and saved lots of time writing colour routines, thanks. Ported to ARM and wrote my own library to lit each pixel and set RGB colour.

      Reply

      seaworld

  • Dec 9, 2015 - 3:03 AM - Evghenii Comment Link

    Hi.

    Very good tutorial, but I think there is an error on the picture 2 “Arduino & WS2812 – Only running on external power supply”. I guess when you connect Arduino to external power supply in this case external +5V (DC) should be connected to Vin pin of the Arduino, but on your chart it is connected to +5V (that i theory should be used to supply detectors connected to Arduino).

    Regards

    Evghenii

    Reply

    Evghenii

    • Dec 9, 2015 - 8:08 AM - hans - Author: Comment Link

      Hi Evghenii,

      I guess you’re right that usually Vin is being used, instead of +5V.
      And even though the displayed setup works just fine (I’ve been using this setup for almost 2 years now on a daily basis), I should probably look into changing the picture to be really 100% correct.

      The problem is that I’m traveling until next month, so I won’t be near my stuff in the next weeks to make the modifications … 

      Reply

      hans

      • Aug 28, 2016 - 1:23 PM - Kevin Z Comment Link

        Actually the VIN pin is connected to the voltage regulator, which at least on the UNO is supposed to be fed with 7-16V. When using a (regulated?) 5V source the 5V terminal can be properly used as an input.

        Reply

        Kevin Z

  • Dec 21, 2015 - 6:38 PM - bogdan Comment Link

    Thank you for sharing your work !

    Reply

    bogdan

    • Dec 21, 2015 - 6:56 PM - hans - Author: Comment Link

      You’re welcome Bogdan, and thanks for taking the time to post a “Thank you” 

      Reply

      hans

  • Dec 24, 2015 - 2:07 PM Comment Link
    PingBack: www.stgomakerspace.com

    […] códigos para programar los Leds fueron sacados de Tweaking4all.com para los que quieran practicar y aplicar otros diseños de Leds para reemplazar ornamenta […]

  • Dec 26, 2015 - 9:15 AM - Chuck Comment Link

    Hans,

    Fantastic site!   I just got a Arduino Uno starter kit from Amazon and waiting for a 1m strip of WS2812 lights to arrive as I have a project I am working on for a holistic friend of mine.    I’m 50 and new to all of this, but from my research,  using the Arduino  and the light strip is my best way to go here,  so I am learning as I go now.

    I have to create a 7 led light strip that goes in the following order   LED1 always red,  number 2 always orange,  3=yellow, 4=green, 5=blue, 6=indigo and 7=violet.

    What I need the sketch to do is run for about 10 minutes in a random format where 1 of the 7 led lights will light up for a second or two and other lights remain off and then the next random led lights up.   Then after 10 minutes,  I need the strip to then run a continuous simple chase format where LED1 lights up for a second or two (all other lights off), then goes off.  Then LED 2 goes on (all others off) , then the pattern continues #3 thru #7 then start over again at #1.

    I’ll be reading more of your posts,  but any advice on how to proceed would be greatly appreciated!

    Reply

    Chuck

    • Dec 27, 2015 - 8:39 AM - hans - Author: Comment Link

      Hi Chuck,

      Maybe (considering the potential code we’d be posting) it’s better to start a topic in our Arduino Forum. Any post in the forum, I read … 
      It does not sound like this would be a very complicated project, so I most certainly am willing to help you with this. 

      Reply

      hans

      • Dec 27, 2015 - 11:09 AM - Chuck Comment Link

        Thanks Hans,  I appreciate the help!     I will start a topic in the Arduino Forum,  thank you for pointing me the way!  :-)

        Reply

        Chuck

      • Dec 28, 2015 - 9:08 AM - hans - Author: Comment Link

        I’ll be looking forward to your post 

        Reply

        hans

  • Jan 3, 2016 - 2:09 PM - David Comment Link

    Hello Hans,

    I have been following this thread with interest.

    I am a complete novice but have made some limited progress with some modifications as you will see from the attached code.  I would be extremely grateful if you could point the way with the next stage as a variation on your Strobe code.  I have so far modified it to produce the following: –

    1. A second strobe function including and an additional integer that I have called BlackDelay which needs to have a different integer value to the FlashDelay.

    2. Corresponding duplicate function and statement blocks for the second strobe function.

    What I would like to do is make each Pixel individually addressable with a predetermined fixed colour/colour combination and strobe sequence.  At the moment I am using 5 PL9823 addressable RGB LEDS for testing but will eventually require >100.

    Not every one of the intended 100 or so Pixels will be unique, as in some Pixels may share the same colour/colour combination and strobe sequenceI and I am assuming that if there are say 80 variants, that these could be configured in setup and then called from a loop function for each Pixel?

    My modified code is as follows:

    #include <Adafruit_NeoPixel.h>
    #define PIN 6
    #define NUM_LEDS 5
    // Parameter 1 = number of pixels in strip
    // Parameter 2 = pin number (most are valid)
    // Parameter 3 = pixel type flags, add together as needed:
    //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
    //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
    //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
    //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_RGB + NEO_KHZ800);

    void setup() {
      strip.begin();
      strip.show(); // Initialize all pixels to 'off'
    }

    // *** REPLACE FROM HERE ***
    void loop() {
      // Strobe0
      Strobe0(0x00, 0x00, 0xff, 1, 500, 1000, 500);
      // strobe
      Strobe1(0xff, 0xff, 0x00, 2, 200, 1000, 3000);
    }

    void Strobe0(byte red, byte green, byte blue, int Strobe0Count, int Flash0Delay, int Black0Delay, int End0Pause){
      for(int j = 0; j < Strobe0Count; j++) {
        setAll(red,green,blue);
        showStrip();
        delay(Flash0Delay);
        setAll(0,0,0);
        showStrip();
        delay(Black0Delay);
      }
     
     delay(End0Pause);
    }

    void Strobe1(byte red, byte green, byte blue, int Strobe1Count, int Flash1Delay, int Black1Delay, int End1Pause){
      for(int j = 0; j < Strobe1Count; j++) {
        setAll(red,green,blue);
        showStrip();
        delay(Flash1Delay);
        setAll(0,0,0);
        showStrip();
        delay(Black1Delay);
      }
     
     delay(End1Pause);
    }
    // *** REPLACE TO HERE ***

    void showStrip() {
     #ifdef ADAFRUIT_NEOPIXEL_H
       // NeoPixel
       strip.show();
     #endif
     #ifndef ADAFRUIT_NEOPIXEL_H
       // FastLED
       FastLED.show();
     #endif
    }

    void setPixel(int Pixel, byte red, byte green, byte blue) {
     #ifdef ADAFRUIT_NEOPIXEL_H
       // NeoPixel
       strip.setPixelColor(Pixel, strip.Color(red, green, blue));
     #endif
     #ifndef ADAFRUIT_NEOPIXEL_H
       // FastLED
       leds[Pixel].r = red;
       leds[Pixel].g = green;
       leds[Pixel].b = blue;
     #endif
    }

    void setAll(byte red, byte green, byte blue) {
      for(int i = 0; i < NUM_LEDS; i++ ) {
        setPixel(i, red, green, blue);
      }
      showStrip();
    }

    If you could give me some idea as to the methodology for this more complicated variant of your original code I would be extremely grateful.

    Reply

    David

    • Jan 5, 2016 - 2:09 PM - hans - Author: Comment Link

      Hi David,

      I’d recommend taking this to the forum.
      On top of that: I’m traveling so I won’t be able to give you anything good until I get back home, which will be in a few days. 
      If you decide to move this to the forum;
      – Post a link to the Forum post here would be great for others that might be interested 
      – I do see every post in the forum, so I won’t forget or miss it 

      Sorry for the delay …

      Reply

      hans

      • Jan 6, 2016 - 12:11 PM - dp34067 Comment Link

        Hello Hans,

        Thanks for your reply.  Despite being logged on as dp34067 I am unable to create a new topic in the forum.

        Am I barking up the wrong tree and should I just be replying to one of the existing topics?

        Reply

        dp34067

        • Jan 6, 2016 - 12:19 PM - hans - Author: Comment Link

          Hmm, you should be able to create a new topic.
          Can you try reloading the page and try again (if you haven’t done that already)?
          If not then that would be a problem  – I just checked your user profile and it’s set to “participant”, so you should be able to create a new topic.

          I did notice however that the login dialog doesn’t always seem refresh the page as it should, after loggin in.
          Please let me know if this issue persists. I’ll do some investigating on my end as well.

          Reply

          hans

    • May 26, 2018 - 10:34 PM - Richard Amador Comment Link

      Hello i have a question, first off thank you for all the code and great job, second I try to put the code into Arduino and compile it, it keeps saying ‘meteorrain’ was not declared in this scope any idea of how i could fix that?

      Reply

      Richard Amador

      • May 27, 2018 - 9:25 AM - hans - Author: Comment Link

        Hi Richard,

        it’s a little hard to determine why you get this message without seeing the code.
        Please do not post the full code here though, rather use the forum for that to avoid that the comment sections gets too long.
        The most common reasons why you’d see that message:

        1) You copied the code from this website and are one of the very unlucky users where the Arduino IDE is doing something goofy with it.

        fix: Copy and Paste the sketch from the website into Notepad, Copy again from there and paste it in the Arduino IDE – this typically filters invisible characters causing issues.

        2) You’ve typed the code and made a typo somewhere.

        fix: Look around the “void meteorRain(…)” function definition. You may have missed a “}” or a “;” (quite common).

        Reply

        hans

  • Jan 6, 2016 - 2:07 PM - dp34067 Comment Link

    Hello Hans,

    I switched browsers from Firefox to Google Chrome and all seems well, but that may be a coincidence!

    Reply

    dp34067

    • Jan 8, 2016 - 3:25 AM - hans - Author: Comment Link

      I tested it here with a fake username in Chrome and Safari – it worked just fine unfortunately. So I’m guessing it was a caching issue.
      I’ll keep an eye on it and take a better look once I get back home. Maybe one or the other thing is caching where it shouldn’t.

      Reply

      hans

  • Jan 20, 2016 - 1:03 PM - Adnan Comment Link

    Hello;

    nice effects and thanks for writing such a informative tutorial.

    But i am here with a stupid question :D

    how to display a static color using arduino?

    i want to make led strip (ws2812b) to show a static color lets say only red. So that when i start arduino my led strip would only display red color and continue to display it.

    Reply

    Adnan

    • Jan 21, 2016 - 4:29 AM - hans - Author: Comment Link

      Hi Adan,

      There are no stupid question ….  

      Setting the entire strip in one color can be done (in this framework) with:

      setAll(red, green, blue);

      So for example for setting all LEDs to blue:

      setAll(0,0,0xff);

      Reply

      hans

  • Mar 2, 2016 - 4:23 PM - Hadj Comment Link

    Just wanna thank you for this great tutorial with flexible codes and videos! Awesome!

    Reply

    Hadj

    • Mar 3, 2016 - 2:39 AM - hans - Author: Comment Link

      Thank you for taking the time to post a “Thank you” Hadj!
      It’s much appreciated  …

      Reply

      hans

  • Mar 6, 2016 - 2:24 AM - matt.h Comment Link

    Running Arduino 1.6.3 with FastLED 3.0, Arduino Nano 3, 328 atmega, WS2812B leds. LEDs, when setup with RGB ordering, output green for red, and red for green. Blue is fine.Switching to GRB ordering, all the LEDs in my strip turn green, with hints of other colors (ie a flashing “red” LED will be a slightly pulsing fully lit green LED.The coloring of the strip does not occur in the RGB ordering – but obviously, the colors are backwards.Any thoughts?

    Reply

    matt.h

    • Mar 7, 2016 - 3:38 AM - hans - Author: Comment Link

      Hi Matt,

      there are several ways of ordering the LED colors, not sure why some (often Chinese) manufacturers choose a different order. You’ve already tried RGB and GRB, if I understand you comment correctly. As far as I can see, these combinaties should be valid, and you’d have to test which one works for your strip:
      RGB,  RBG, GRB, GBR, BRG, and BGR.

      Since I haven’t ran into this issue, I would not be able to predict which one would work for you.

      Note: When you set all LEDs to WHITE then the color scheme should not matter, since all values (R, G and B) should be FF.
      However ,… if you strip does not light up white, then there might be another problem.

      Reply

      hans

  • Mar 30, 2016 - 2:17 PM - Nils-Johnny Friis Comment Link

    I am “newbie” with Ardunio and my English is not sooooo good (I read better than I write). So I have to use Google translator to help me to write to you.
    But I hope you can help me.

    I visited this site: //www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/. I liked what I saw and tried out all the sketch on this site. 

    So my question is: Can I find a sketch/Framework that contains all the effect-sketch in the Framework?

    I want to teach me the use of functions (I would think that I have to use functions to “connect” sketch together?), but still has a lot before I understand their use. Unless there is a sketch which shows that use of all smal sketch in the Framework.

    I would be very grateful if you could write me the sketch to show me all the effect-sketch in use in Framework.

    You can also post it on your site so that other people can use it. :)

    I want to study how you put together all the sketch and run them together, and use off function to be beeter to write code. I want to make myself a great Christmas stuff! :)

    I use Adafruit_NeoPixel library. I would be very happy for your help.

    Reply

    Nils-Johnny Friis

    • Mar 31, 2016 - 4:58 AM - hans - Author: Comment Link

      Hi Nils-Johnny,

      you’re English is actually pretty good – with or without help from Google 

      I suppose theoretically, you could put all effects into one sketch. It might be however, that you run out of memory (depending on the Arduino model you’re using).
      First you’d have to copy all the functions I have mentioned here into the same sketch – just keep adding them at the end each time.

      Next you’ll have to look at the “loop()” function where we call these functions – this is where you have to be creative and see how you’d like to call them (what order etc).

      Posting the entire code here would be a bit large, so I did post it in the forum … You’ll find the FastLED and NeoPixel versions in this post.

      Reply

      hans

  • Apr 11, 2016 - 4:04 PM - Greg Wren Comment Link

    OMG…you know how cool it is when you find EXACTLY what you are looking for on the magical interwebs?  Thanks so much for sharing your knowledge on this…just got my first set of pixels to make a marquee sign, and have been trying to explore both of the libraries you use here on my own…this write-up pulled it all together for me!  Now I have them doing exactly what I want, and have come up with some different ideas that I never would have thought of…

    Thanks for sharing your knowledge!

    Reply

    Greg Wren

    • Apr 11, 2016 - 5:08 PM - hans - Author: Comment Link

      Thanks Greg!

      It’s equally awesome to see a “Thank you” note like this one – it’s so much appreciated! Thanks! 

      (and yes; playing with these LED strips is awesome! )

      Reply

      hans

  • Apr 15, 2016 - 8:10 AM - mikewolf Comment Link

    Hi,

    These LED routines are all great. I’m trying to combine a few of them into one program and have a variable chose which one to display. I’ve only tested a few so far, but I found that the Bouncing colored balls gets stuck and does not return to the loop. I added a  line after showstrip; to break if the variable is not set to the value for that routine. I thought I’d mention this in case someone else is attempting to do the same thing. 

    Reply

    mikewolf

    • Apr 15, 2016 - 8:57 AM - hans - Author: Comment Link

      Thanks Mikewolf 

      Glad you’re having fun with LED strips haha (so do I!).

      I have not run into this issue before, but it makes sense since we keep the balls bouncing using “while(true)”.
      You could of course add a timer or something and then modify the while to something that checks if it has been bouncing for a certain time.

      A few other users have been toying with combining the effects, see this forum post and this one.
      Not sure how helpful they will be of course for your project, just thought I should mention it … 

      If you have created a cool project, feel free to post it in the forum!
      I’m sure others might enjoy it as well – but it’s totally optional of course … 

      Reply

      hans

  • Apr 20, 2016 - 7:14 PM - mikewolf Comment Link

    Hi ,

    I added the Cylon and New Kitt to my Program and noticed every time these routine starts over, most of the leds briefly flash white. I cant see anything in the code that could be causing this. Any ideas?

    Reply

    mikewolf

    • Sep 12, 2019 - 6:04 AM - flow in Comment Link

      I had the same issue with my 300 led strip.

      It turns out that the control voltage needs to be in close match with the supply voltage.
      I used a transistor, with the arduino connected to the base (with a 100k pulldown resistor) and the supply voltage on the collector, then connected the strip to the emitter and all the glitches went away.

      Maybe you could just use a pulldown resistor on its own, thinking about it. The glitches do seem to be data rate associated.

      Reply

      flow in

  • Apr 20, 2016 - 8:12 PM - mikewolf Comment Link

    I figured it out. I forgot to put a break in between one of my “switch case” statements. It was briefly going to a function that just called up all white leds.

    Reply

    mikewolf

    • Apr 21, 2016 - 6:31 AM - hans - Author: Comment Link

      Hi MikeWolf!

      See; that’s what I like to see haha … I sleep, while the user finds a problem and resolves it. Awesome! 
      Glad to hear it works now!

      Reply

      hans

      • Apr 21, 2016 - 7:44 PM - mikewolf Comment Link

        Once I get the NewKitt routine to change colors everytime  the eyes hit the sides or each other, my life will be complete

        Reply

        mikewolf

        • Apr 22, 2016 - 5:24 AM - hans - Author: Comment Link

          Hi MikeWolf,

          You could change color in the bounces in the NewKITT function. Just a dirty hack, but say you’d want to use only 2 colors (red and white):

          void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
            RightToLeft(0xff, 0, 0, EyeSize, SpeedDelay, ReturnDelay); // red
            LeftToRight(0xff, 0xff, 0xff, EyeSize, SpeedDelay, ReturnDelay); // white
            OutsideToCenter(0xff, 0, 0, EyeSize, SpeedDelay, ReturnDelay); // red
            CenterToOutside(0xff, 0xff, 0xff, EyeSize, SpeedDelay, ReturnDelay); // white
            LeftToRight(0xff, 0, 0, EyeSize, SpeedDelay, ReturnDelay);
            RightToLeft(0xff, 0xff, 0xff, EyeSize, SpeedDelay, ReturnDelay);
            OutsideToCenter(0xff, 0, 0, EyeSize, SpeedDelay, ReturnDelay);
            CenterToOutside(0xff, 0xff, 0xff, EyeSize, SpeedDelay, ReturnDelay);
          }

          Obviously, this can be done nicer, and I don’t know if only 2 colors would be OK for your purposes.

          Reply

          hans

          • Apr 22, 2016 - 7:49 PM - mikewolf Comment Link

            Hi Hans,

            I got it to do exactly what I wanted. I was already using the bouncing color ball routine, so I used the array to call up the different colors as it switches from left to right, outside to center, etc. I’m just started learning this arduino stuff. I’ve been programming pic micros in assembly language for the past 25 years. Using these addressable LEDs is a great way to learn a new language. FYI, I’m using a Teensy 3.2 as my processor. 

            mikewolf

          • Apr 23, 2016 - 4:29 AM - hans - Author: Comment Link

            Hi MikeWolf!

            Glad to hear that! 

            Hey, for me, a lot of this stuff is new as well. I used to play with the BASICStamp (far from as advanced as using assembly) for a while, but the Arduino made things a lot easier. Also good to know that Teensy pulls this off!

            hans

  • Apr 22, 2016 - 12:53 PM - imdr5534 Comment Link

    Does anyone know how to program these effects so that you can select  a button for each or one button to scroll thru each with a random selector as well?  

    I built a crosley type jukebox with digital screen and Kodi with 4 pairs of WS2811 LED’s.    10 LED’s on 2 strings vertical and  9 LED’s on 2 strings horizontal.  

    I have tried piecing together Fastled Multiple string code with Fastled DEMO100 code but only the first effect lights up.

    (Apologies: due to the length of the code, I had to move it to the forum: see this post)

    Reply

    imdr5534

    • Apr 23, 2016 - 3:35 AM - hans - Author: Comment Link

      Hi Imdr5534 ….

      I had to move the lengthy code to the forum. Apologies for that.
      I’ll post an answer there.

      Reply

      hans

  • Apr 30, 2016 - 10:09 PM - KTTJ Comment Link

    Utterly fantastic.  Thank you so much for taking the time to create, write up, and share all of these fantastic light displays with us!  You have a true gift and a generous heart. 

    Since your code has saved me at least a day’s worth of work, I would happily donate to your site for your time and effort, but I’d rather all of the funds go directly to you (instead of 90% through Flattr).  Are there alternatives (like PayPal) or something similar?  I’m US-based, if that makes a difference.

    Thanks again!  I really appreciate your work!

    Reply

    KTTJ

    • May 1, 2016 - 4:43 AM - hans - Author: Comment Link

      Hi KITJ!

      Thank you for your kind compliments – that is always a motivator to keep going .
      You can donate through PayPal, although it’s not required yet very much appreciated.
      Unfortunately, PayPal did not allow me to have a donate button but I do have a PayPal account. I’ll email you the details. 

      Reply

      hans

  • May 18, 2016 - 8:56 PM - abarrelofmonkeys Comment Link

    Absolutely Amazing! You truly are the keymaster of NeoPixels. I absolutely love WS2812’s and have been playing with them for about 6 months now. This is by far the best use of them I have found. I was hoping you could point me to an example that uses your examples with a switch. I have been trying for a few days now to get your code with “all effects” to operate through a switch case instead of time delays. I have had no luck getting a switch to control even two shows. I must be missing something very simple like checking my switch at the wrong times. Hopefully there is something out there for me? Otherwise you have made a wonderful contribution to NeoPixels.

    (int thanks, thanks++);

    Reply

    abarrelofmonkeys

    • May 21, 2016 - 3:30 PM - hans - Author: Comment Link

      Hi ABarrelOfMonkeys! 

      Thank you very much for the compliment. 
      As for using a switch, I recall another user asking for something like this as well (see this comment, this forum topic might get you started as well).

      Unfortunately, I’m traveling for work, so I have little chance and time to help you on your way.
      I should be back in about 2 weeks, which would clear my schedule a little more …

      Reply

      hans

  • Jul 11, 2016 - 4:13 AM - hans - Author: Comment Link

    For those interested in effects for Christmas, look at Spike’s project in this forum post.

    Reply

    hans

    • Jul 19, 2016 - 7:25 PM - spike Comment Link

      Hi Hans,

      Thank you, I hope others find it useful.

      As KITJ! asked above, would you also send me the details so that I can buy you a drink please?

      Your preferred currency too if you would be so kind.

      I’m still working on more stuff for Christmas, although the wife doesn’t think I should go overboard with the amount of LEDs. As if I would 

      Reply

      spike

      • Jul 20, 2016 - 10:13 AM - hans - Author: Comment Link

        Thanks Spike,

        I could use a drink right now haha (it’s super hot here right now).
        You can donate through PayPal (email: hans at luijten dot net) … pick a subject like “drink” or “LEDs”. PayPal doesn’t allow me to place a Donate Now button on my website ….

        Hahaha once you get the hang of it … you WILL go overboard with the LED strips … don’t forget to send pictures!!!!
        It’s awesome stuff to play with …

        Reply

        hans

        • Jul 21, 2016 - 1:17 AM - spike Comment Link

          Hi Hans,

          Indeed, it’s very hot here at the moment too.

          Yes, I read your post about PP saying that you couldn’t use a link, it’s a real shame.

          You’re quite right, LEDs are seriously addictive, I have been playing with them for a couple of years. This is one of my creations https://youtu.be/oiXbXCQdf8c

          But thanks to you, I am getting better at the coding side of it.

          Is there a list of the NeoPixel or FastLED commands anywhere?

          A drink should be in your inbox   Enjoy!

          Reply

          spike

          • Jul 21, 2016 - 3:12 AM - hans - Author: Comment Link

            You’re the best Spike!!! 

            Perfect timing for sending me a few drinks! 

            Oh wow! Love the YouTube video you posted – that’s so cool! I better start looking into an effect like that as well … 

            As for lists of available commands, I found this keyword list for NeoPixel, and this FastLED reference. The one for FastLED actually had a good explanation with it. Hope that helps … 

            hans

  • Jul 13, 2016 - 11:33 PM - Anthony Comment Link

    Hi, I’m new to all of this LED and Audrino stuff, I was wondering if it is at all possible to create a “Chase” effect or any of the effects posted here for that matter, using a single color LED strip with UV LED’s? 

    Reply

    Anthony

    • Jul 14, 2016 - 4:59 AM - hans - Author: Comment Link

      Hi Anthony,

      I would assume this is very well possible,… if you can find a LED strip with UV LED’s.
      Then the next question would be finding a library that supports that particular LED strip.

      Unfortunately, I have not yet seen a LED strip with just UV LEDs.

      Reply

      hans

      • Jul 14, 2016 - 10:35 AM - Anthony Comment Link

        First off, thank you Hans for writing back so quickly. I really do appreciate it and your your time. So yes to, there are lots of strip out there with UV LED’s but to my understanding they are all analog. I can’t seem to find a single color digital strip anywhere let alone one that is UV. This is basically for a computer build that I’m putting together.  The other question I came up with is permanent placement of the arduino in side the computer. Is it possible/ok to, substitute the external 5v power supply you in your diagram with a molex connection to the 5v 30a DC rail on a ATX computer psu? 

        Again I really do appreciate your help!!!!!

        Reply

        Anthony

        • Jul 15, 2016 - 4:33 AM - hans - Author: Comment Link

          Hi Anthony,

          you’re most welcome.

          I think the problem with Analog strips is that you cannot address the LEDs individually, so making that work with an Arduino might not be possible. I did find this Arduino Forum Topic, which might be of interest.

          As for powering the Arduino+LEDs with your computers PSU; that should work (5V 30A is definitely enough). Just make sure that you get a PSU with some extra watts available to power your PC (mainboard, disks, videocard, etc) and the LEDs. Placing the Arduino itself in the case would not be a problem though.

          Reply

          hans

          • Jul 17, 2016 - 11:30 PM - Anthony Comment Link

            And So Again, I’m calling on your expertise……..

            So I went and got an Arduino UNO Starter kit, ordered a whole mess of led strips (waiting for them to be delivered). Downloaded the Arduino Software and the Fast LED Library. No matter what i do whether its open a file from the fast led library or just copy and past it from here. All I get are error messages. I have to say beyond the simple downloading and uploading of files or copying and pasting the code. I truly have no clue as to what I’m doing or looking at, or even what I’m doing wrong. Whatever help you can give would be greatly appreciated.

              

            Anthony

          • Jul 18, 2016 - 2:59 AM - hans - Author: Comment Link

            Hi Anthony,

            Could you post the exact steps and error message?

            hans

  • Jul 18, 2016 - 12:52 PM - Anthony Comment Link

    Ok, so ill start from the beginning. 

    I downloaded the arduino ide, installed the drivers. All apears properly 

    In the arduino software I went to TOOLS>BOARD and made sure my UNO was selected, Same thing for the COM

    All seems to be working properly, I even ran through the blink project in getting started everything functioned as it should.

    I tried several ways to use the FASTLED library, Ill go over each one:

    #1) Sketch>Include Library>Add .ZIP Library, When the window opens, Downloads> LEDEeffects_Sources.zip> Open

    Then I get:

    Arduino: 1.6.7 (Windows 10), Board: “Arduino/Genuino Uno”

    Specified folder/zip file does not contain a valid library

    This report would have more information with

      “Show verbose output during compilation”

      enabled in File > Preferences.

    #2)Manuallly extrating the files to the arduino library: I followed the Instructions from here: https://www.arduino.cc/en/Guide/Libraries#toc5

    After restarting the IDE I get a window:

     ignoring bad library name

    The library “FastLED Examples” cannot be used.

    Library Names can only contain basic letters and numbers.(ASCII only and no spaces, and it cannot start with a number)

    GRRRRRRRRRRR You can See My fustration, and oviously just copy and pasting the code doesnt work. 

    Really Hans, thank you.

    Reply

    Anthony

    • Jul 19, 2016 - 4:35 AM - hans - Author: Comment Link

      Hi Anthony,

      I can totally understand the frustration …  it’s too bad that the Arduino IDE doesn’t handle GitHub ZIP’s all that well (see also here). You could try that older FastLED library and the Arduino IDE could automatically update it to the latest version.

      So I quickly started up a Windows virtual machine to describe it for you., and installed the latest Arduino IDE (1.6.9).
      After the application started, I went to the menu: Sketch -> Include Library -> Manage Libraries. This will open a window, which takes a bit to load everything it can find. But once it’s done, you can type “fastled” in the “Filter your search…” box. 
      FastLED should appear here. Click it and the button “install” will appear. Installation takes seconds. Once done, click “Close” and the FastLED library should be available. 

      Reply

      hans

      • Jul 19, 2016 - 4:36 AM - hans - Author: Comment Link

        p.s. you’ll find the examples in File->Examples->FastLED 

        Reply

        hans

        • Jul 19, 2016 - 3:46 PM - Anthony Comment Link

          Ok, so I was able to find the library and install it through the IDE like you said. Much to my delight, the effects that I want to use are not included…… sigh……The effects that I’m looking for are:

          Newkitt, Strobe, RunningLights, Bouncing balls multi color

          Also saw this one on you tube https://www.youtube.com/watch?v=_wkTtAk2V_k

          My Project: I’m building a new High End Gaming Computer, with a custom liquid cooling system, of which the main focal point of the system will be the a custom built reservoir tank. Everything inside the case will be visible through large side panel windows. I plan on cutting the led strip down to length, to fit inside a sealed tube, inside the center of the reservoir and have the LED’s running the desired effects while the coolant is swirling around the reservoir.

          So obviously I will have to change the led count from 60 to whatever it is that’s on the strip after I cut it. Correct? Hopefully……..

          I ordered 2 strips of Waterproof WS2812 LEDS one with a 60 LED count, One with a 144 LED count. Again in theory either should work as long as I change the LED count in the sketch accordingly?

          I also “get” the part in the code, on how to tweak the colors.

          So simply put, where can I get the the code, for the examples I gave from beginning to end, simply copy and paste into a sketch, save it, use it, and works?

          Reply

          Anthony

          • Jul 20, 2016 - 10:20 AM - hans - Author: Comment Link

            Hi Anthony … good to hear you’ve got the library running now 

            Looks like you’re starting an interesting project (send pictures when you’re done!!).
            Yes you’d have to reduce the LED count to make it fit the strip/LED count you’re actually using.
            The examples can be found in the code here as well. There is pretty much no overhead in my code – I just made it so it can be used with both libraries.

            As for combining effects, take a look in the Tweaking4All Arduino Forum (goor place to ask questions too). It’s not super extensive, but this topic for example discusses how to put multiple effects together. For most effects, it’s a matter of copy and paste, for a few others it takes a little bit more work … but it can be done! 

            hans

  • Jul 20, 2016 - 2:15 PM - Anthony Comment Link

    I don’t think I’m going as far as combining effects. Just switching them around as the mood suits me. I’ll definitely be posting up some pics soon as I get things up and running. Might even do a you tube videos on the build too.

    Reply

    Anthony

    • Jul 21, 2016 - 3:06 AM - hans - Author: Comment Link

      Awesome! 

      Feel free to post links here, or send me pictures (I can place pictures in the comments for you). 

      Reply

      hans

  • Jul 23, 2016 - 4:23 AM - hans - Author: Comment Link

    For those interested:

    Spike posted the code and such for how to make an awesome Christmas star with effects in this forum post.
    A YouTube video demo can be found here.

    Reply

    hans

  • Jul 23, 2016 - 4:00 PM - Anthony Comment Link

    Hans, Can you please take a look at this and tell me what exactly is wrong with it? 

    When I try to verify I get “setAll” was not declared in this scope…..

    #include “FastLED.h”

    #define DATA_PIN 6

    #define LED_TYPE WS2812B

    #define COLOR_ORDER GRB

    #define NUM_LEDS 144

    CRGB leds[NUM_LEDS];

    void loop() { 

      // Slower:

      // Strobe(0xff, 0x77, 0x00, 10, 100, 1000);

      // Fast:

      Strobe(0xff, 0xff, 0xff, 10, 50, 1000);

    }

    void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){

      for(int j = 0; j < StrobeCount; j++) {

        setAll(red,green,blue);

        showStrip();

        delay(FlashDelay);

        setAll(0,0,0);

        showStrip();

        delay(FlashDelay);

      }

     

     delay(EndPause);

    }

    Reply

    Anthony

    • Jul 23, 2016 - 4:08 PM - Anthony Comment Link

      P.S.

      It seems as though the set all error message comes up on every sketch I copy from here. So I’m sure it’s just me, missing something.

      Reply

      Anthony

    • Jul 24, 2016 - 3:51 AM - hans - Author: Comment Link

      Hi Anthony,

      you forgot to copy the “framework” (link = see above).

      In the framework code (depending which library you choose, in your case FastLED), you’ll need to replace the following code with the code for the effect:

      // *** REPLACE FROM HERE ***
      void loop() { 
        // ---> here we call the effect function <---
      }
      // ---> here we define the effect function <---
      // *** REPLACE TO HERE ***
      Reply

      hans

      • Jul 25, 2016 - 12:08 AM - Anthony Comment Link

        Thank You, Thank You, Thank You, Thank You…………. Finally its working just as it should.

        Reply

        Anthony

  • Jul 29, 2016 - 12:29 PM - Steve Comment Link

    Hi Guys

    Looking for major help, I have made an intinity mirror which is using 205 ws2812B what I would like to do is use the fire sketch (which i can of course) but what i cannot do or maybe its not possiable is to have 2 starting point with the flames using 100 leds.

    starting point (1) leds 1 to 100

    starting point (2) leds 205 to 105

    The idea is that it looks like the flames are starting at the same point and lapping round the mirror

    I really enjoy working with the arduino and leds but sometimes its so bloody frustating :)

    If you think its not possiable let me know as i will then give up on that idea, on a postive note if it is any help would be much appreciated

    Fantastic page by the way

    Reply

    Steve

    • Jul 30, 2016 - 3:36 AM - hans - Author: Comment Link

      Hi Steve,

      thanks for the compliment 

      I wouldn’t think of it as impossible, would it be OK if both sets behave the same with the fire effect? Or should they be different?

      p.s. it’s better to discuss this in our Arduino Forum, otherwise the comments in this topic become too much – I took the liberty to start this topic for you question.

      Reply

      hans

      • Jul 30, 2016 - 3:49 AM - Steve Comment Link

        Hi Hans

        Thank you for your reply, if they were the same for a start then I dont think that would matter if I like the effect , I was trying a sort of New Kitt with the flames instead of the chasing lights but you guessed I could get it to work

        Reply

        Steve

      • Jul 30, 2016 - 4:01 AM - hans - Author: Comment Link

        Hi Steve,

        you’re most welcome!

        I posted a code suggestion in this forum topic
        Give it a try – it should mimic what you’d like to see – but I’m unable to test this, since I don’t have my hardware with me.

        Reply

        hans

  • Jul 30, 2016 - 3:51 AM - Steve Comment Link

    I couldnt get it to work (typo)

    Reply

    Steve

  • Jul 30, 2016 - 4:44 AM - ap0ll0 Comment Link

    Im back on here as im unable to login on the forum username ap0ll0 password as been sent but unable to get logon

    do you know i have been trying on and off for 3 weeks to do what you have just put on the forum yes its working the only problem is the start point for 0 to 99 is starting at 99

    man i wish i could do what you have just done

    Reply

    ap0ll0

    • Jul 30, 2016 - 5:09 AM - ap0ll0 Comment Link

      Hi Ap0ll0!

      I just emailed you a new password – I have no idea why the forum acts up every now and then. Time to start looking for a new forum for WordPress I suppose.

      I’ll add a comment to the forum topic again … 

      Reply

      ap0ll0

      • Jul 30, 2016 - 5:16 AM - hans - Author: Comment Link

        As for being able to do this your self; practice … and believe me, I’m not a great coder either … it just takes a lot of playing with code to get a feel for it. 

        Reply

        hans

      • Jul 31, 2016 - 4:17 AM - hans - Author: Comment Link

        Interested in cool effects and uses of effects, checkout App0ll0’s work in the forum … it looks awesome! 

        Reply

        hans

  • Aug 7, 2016 - 1:39 PM - chemix Comment Link

    hi how to do that was to be turned on and off by pressing button

    Reply

    chemix

  • Aug 29, 2016 - 8:45 PM - Kent Caldwell - Author: Comment Link

    Awesome guide and resource, many thanks and praise for all of the useful info, demos, and code! Can’t wait to fiddle with these-

    Reply

    Kent Caldwell

  • Sep 16, 2016 - 5:51 PM - tidehunter Comment Link

    Hi Hans!

    Could you help me, please?

    I want to combine different effects in 1 sketch, but Bouncing Balls effect (that I rly like) is  endless. What shall I change in code to limit number of Bouncing Balls cycles?

    Reply

    tidehunter

    • Sep 17, 2016 - 8:37 AM - hans - Author: Comment Link

      Hi TideHunter,

      I’d start with playing with the while loop in line 26 (while (true) {), maybe change that to some like this:

        ...
       int whilecounter=0;
        ...
        while (whilecounter<100) {
          whilecounter++;
          for (int i = 0 ; i < BallCount ; i++) {
            TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
            Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
        
            if ( Height[i] < 0 ) {                      
              Height[i] = 0;
              ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
              ClockTimeSinceLastBounce[i] = millis();
        
              if ( ImpactVelocity[i] < 0.01 ) {
                ImpactVelocity[i] = ImpactVelocityStart;
              }
            }
            Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
          }
        
          for (int i = 0 ; i < BallCount ; i++) {
            setPixel(Position[i],red,green,blue);
          }
          
          showStrip();
          setAll(0,0,0);
        }

      Just a crude example of how we make the infinite look (while(true)) a finite loop.

      ps. If you’d like to discuss the code, please consider starting a forum topic in the Arduino Forum. Just to avoid that the comments here become very long.

      Reply

      hans

  • Oct 23, 2016 - 5:26 AM - jacchavez Comment Link

    Hello!

    I’ve been trying to utilize your hint about random numbers in order to run different functions every time I switch on the arduino, but I keep getting error messages. I try to tie if and if else statements to different functions and numbers but I’ve been unsuccessful. Can you please let me know a better way to think about calling random functions?

    Reply

    jacchavez

    • Oct 23, 2016 - 1:06 PM - hans - Author: Comment Link

      Hi Jacchavez!

      Please start a topic in the forum, so we can exchange code examples without making the comments here too lengthy – I’ll see what I can do to help  

      Reply

      hans

    • Sep 6, 2019 - 6:55 AM - kylegap Comment Link

      That’s exactly what I’m looking for, for my Hot Tub Led light project… I can’t find the topic in the forum… has it been done?

      Reply

      kylegap

      • Sep 7, 2019 - 5:29 AM - hans - Author: Comment Link

        Hi Kylegap!

        I found the forum topic you started (excellent! ) – for you and other, please continue discussion in this forum topic.

        For reference, I’ll post the short fix for this here as well:

        When using the code of the Led Effects All in one project, you could modify it to actually do this.Modify this part:

        void loop() { 
          EEPROM.get(0,selectedEffect); 
          
          if(selectedEffect>18) { 
            selectedEffect=0;
            EEPROM.put(0,0); 
          } 
          
          switch(selectedEffect) {

        to this:

        void loop() { 
          selectedEffect=random(18); // assuming there are 18 effects
          switch(selectedEffect) {

        The entire EEPROM part has been removed and has been replaced by a random selection (0 to 18).

        To improve the randomness, you can add the following line to the void setup() function;

        randomSeed(analogRead(0));

        Hope this helps 

        Reply

        hans

  • Nov 9, 2016 - 12:26 PM - Jesse Comment Link

    Hi Hans! Just joining in the chorus of voices expressing gratitude for your tutorial and examples. Thank you for your time and energy. It certainly helps to add light to my day! Keep it up!

    -j

    Reply

    Jesse

    • Nov 11, 2016 - 7:16 AM - hans - Author: Comment Link

      Hi Jesse!

      Thank you so much for the compliments and taking the time to post it here. It’s so much appreciated and definitely a motivator to keep going!

      Thanks 

      Reply

      hans

  • Nov 12, 2016 - 6:51 AM - mikewolf Comment Link

    HI,

    A while back I posted about using an RS-422 ic to extend the wiring between and arduino and a strip of addressable LEDs to 1000 feet. 

    Since then I’ve added remote control using a Sony IR codes,  a music interface, and made a high power LED pixel using a WS2811 IC and power Mosfets. I was thinking of making an arduino shield that would contain these features as well as a circuit board to make the high power pixel. I put a video on youtube that shows the music interface in action and the high power pixel thats made up of 3 watt red, green and blue LEDs.

    IR remote LEDs

    Reply

    mikewolf

  • Nov 17, 2016 - 12:41 PM - mikeb1479 Comment Link

    Hi there!

    i appreciate you taking the time to upload this, alot of it looks cool, but… i am very much a beginner to this and it looks very unfriendly to me, i have tried with both NeoPixel and FastLED library, and get the same errors no matter what, yet, virtually no explanation on how to fix it :( i get either, NUM_LED not defined or SetAll not defined, and it is frustrating me :(

    i have a strong of 50 WS2811 12mm LEDs i want to make use of for christmas :(

    can you please help me ? D:

    Reply

    mikeb1479

    • Nov 18, 2016 - 7:52 AM - hans - Author: Comment Link

      Hi Mikeb1479,

      I can understand that this might be challenging for beginners, but no worries – I’ll try to help get you started.

      First of all, the general idea was to have a few functions available which are defined in this part (FastLED as an example).

      #include "FastLED.h"
      #define NUM_LEDS 60 
      CRGB leds[NUM_LEDS];
      #define PIN 6 
      void setup()
      {
        FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
      }
      // *** REPLACE FROM HERE ***
      void loop() { 
        // ---> here we call the effect function <---
      }
      // ---> here we define the effect function <---
      // *** REPLACE TO HERE ***
      void showStrip() {
       #ifdef ADAFRUIT_NEOPIXEL_H 
         // NeoPixel
         strip.show();
       #endif
       #ifndef ADAFRUIT_NEOPIXEL_H
         // FastLED
         FastLED.show();
       #endif
      }
      void setPixel(int Pixel, byte red, byte green, byte blue) {
       #ifdef ADAFRUIT_NEOPIXEL_H 
         // NeoPixel
         strip.setPixelColor(Pixel, strip.Color(red, green, blue));
       #endif
       #ifndef ADAFRUIT_NEOPIXEL_H 
         // FastLED
         leds[Pixel].r = red;
         leds[Pixel].g = green;
         leds[Pixel].b = blue;
       #endif
      }
      void setAll(byte red, byte green, byte blue) {
        for(int i = 0; i < NUM_LEDS; i++ ) {
          setPixel(i, red, green, blue); 
        }
        showStrip();
      }

      Paste this in the Arduino IDE editor.

      Now select this section in this code:

      // *** REPLACE FROM HERE ***
      void loop() { 
        // ---> here we call the effect function <---
      }
      // ---> here we define the effect function <---
      // *** REPLACE TO HERE ***

      and replace it with the function you found with the effect you’d like to use, for example for the FadeInOut effect:

      void loop() { 
        FadeInOut(0xff, 0x77, 0x00);
      }
      void FadeInOut(byte red, byte green, byte blue){
        float r, g, b;
            
        for(int k = 0; k < 256; k=k+1) { 
          r = (k/256.0)*red;
          g = (k/256.0)*green;
          b = (k/256.0)*blue;
          setAll(r,g,b);
          showStrip();
        }
           
        for(int k = 255; k >= 0; k=k-2) {
          r = (k/256.0)*red;
          g = (k/256.0)*green;
          b = (k/256.0)*blue;
          setAll(r,g,b);
          showStrip();
        }
      }

      I hope this makes more sense now … please feel free to ask though! 

      Reply

      hans

      • Nov 18, 2016 - 3:16 PM - mikeb1479 Comment Link

        wow!

        thanks so much friend :D

        it worked very well and much easier that you explained it simply to me :), i now have a few cool effects to choose from for christmas tree lighting :D

        i made sure to save them also!

        thanks so very much for your time and your help, it is much appreciated! :D

        Reply

        mikeb1479

        • Nov 21, 2016 - 8:48 AM - hans - Author: Comment Link

          Awesome Mike!

          Glad I could help … have fun with the LED strips (I know I do!). 

          Reply

          hans

          • Nov 28, 2016 - 12:42 PM - mikeb1479 Comment Link

            i have been, theyre now being used as xmas lights :D

            mikeb1479

          • Jan 28, 2017 - 1:08 PM - mikeb1479 Comment Link

            hey,

            sorry to bother you again, but, other night i had a thought, that maybe you would like

            i was thinking of, sound activated WS2811 lighting, using an UNO, microphone and my WS2811 led’s, but, cannot find a decent sketch anyway :|

            was surprised you didnt have one also :o or did it not interest you ? :)

            many htnaks :D

            mikeb1479

          • Jan 29, 2017 - 3:34 PM - gbonsack Comment Link

            Here is a link, which shows driving 7 LED’s, but one could change the solid LED’s to WS2811/12 and define a color or color mix.

            https://www.baldengineer.com/msgeq7-simple-spectrum-analyzer.html

            gbonsack

          • Jan 29, 2017 - 5:49 PM - hans - Author: Comment Link

            Nice! 

            hans

          • Jan 29, 2017 - 9:24 PM - hans - Author: Comment Link

            Hi Mike,

            yes, ginormous LED VU meters is something on my to-do list … unfortunately, all the little projects I’m working on plus and my fulltime job do conflict constantly. I actually prefer working on projects here over my actual job, but … my actual job pays the bills 

            hans

      • Jun 23, 2018 - 3:51 AM - xena2000 Comment Link

        Hey,
        I’ve been playing around with the Fire code, i’ve been running into problems getting it to start and end within a pixel range.
        Any idea what I need to change to achieve this?
        Thanks for all of this has been really helpful!!

        Reply

        xena2000

        • Jun 29, 2018 - 4:34 AM - hans - Author: Comment Link

          Hi Xena2000,

          sorry for the late reply.

          In essence you’d need to change the “for” loops in fire() function. For example (untested):

          void Fire(int Cooling, int Sparking, int SpeedDelay, int FirstLED, int LastLED) {
            static byte heat[NUM_LEDS];
            int cooldown;
            
            // Step 1. Cool down every cell a little
            for( int i = FirstLED; i < LastLED; i++) { // <-- Changed
              cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);
              
              if(cooldown>heat[i]) {
                heat[i]=0;
              } else {
                heat[i]=heat[i]-cooldown;
              }
            }
            
            // Step 2. Heat from each cell drifts 'up' and diffuses a little
            for( int k= LastLED - 1; k >= FirstLED+2; k--) { // <-- changed
              heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
            }
              
            // Step 3. Randomly ignite new 'sparks' near the bottom
            if( random(255) < Sparking ) {
              int y = random(7);
              heat[y] = heat[y] + random(160,255);
              //heat[y] = random(160,255);
            }
            // Step 4. Convert heat to LED colors
            for( int j = FirstLED; j < LastLED; j++) {
              setPixelHeatColor(j, heat[j] );
            }
            showStrip();
            delay(SpeedDelay);
          }

          You can call Fire() the same way as usual, I just added 2 additional parameters (First and Last LED).

          I have not tested this, since I do not have my gear near me. But give it a try (I hope I didn’t overlook anything).

          Reply

          hans

  • Nov 26, 2016 - 10:18 AM - Thiago - Author: Comment Link

    I created an Android application to control it via Bluetooth:

    https://github.com/thiagolr/lightita

    Reply

    Thiago

    • Nov 26, 2016 - 2:49 PM - hans - Author: Comment Link

      Hi Thiago,

      very nice!!! Thanks for sharing!

      Reply

      hans

    • Nov 27, 2016 - 4:07 AM - Spike Comment Link

      Hi Thiango, Thanks for sharing, I would love to try this out and incorporate it into my Christmas lights next year.

      Can you give me more info on how it is implemented please;

      What BT modules does it support? Assuming it would connect to an Arduino etc

      I guess I’m really asking for an idiots guide, including how to install your app to an Android device as there doesn’t appear to be an APK.

      Reply

      Spike

      • Nov 28, 2016 - 4:50 AM - Thiago - Author: Comment Link

        I’m using an HC-05 Bluetooth Module connected on an Arduino Uno, but the Android application should work with any Bluetooth module.

        The Android APK can be found here:

        https://github.com/thiagolr/lightita/releases

        Reply

        Thiago

        • Nov 28, 2016 - 5:28 AM - spike Comment Link

          Thats awesome, thank you.

          Which sketch should be uploaded to the Arduino? I’m assuming it should be ‘lightita.ino’ ?

          What is the ‘effects.ino’ sketch for?

          Sorry for all the questions but I appreciate your support.

          Thank you

          Reply

          spike

          • Nov 28, 2016 - 6:26 AM - Thiago - Author: Comment Link

            You should open the lightita.ino on the Arduino IDE and the effects.ino should be opened automatically on another tab inside the IDE. The effects.ino file contains all the effects, I separated on two different files to keep things organized.

            Thiago

  • Dec 6, 2016 - 1:17 PM - Aldo Comment Link

    Thanks a lot!!!!

    have a nice days!!

    Reply

    Aldo

  • Dec 11, 2016 - 11:28 AM - Andrew Comment Link

    Although a very cool and fantastically laid out article, I find a lot of the code needlessly complex. To me, the big no no’s in an animation that may have button or other controls include:

    • Nested loops
    • Floats
    • Blocking delays

    My other big issue is counting pixels up and down and I’ll use the cylon as an example. Why have all that code to count up and down, when you could just use some basic high school math and use sine waves instead? You could use it to go back and forth, you could use phase shifting and have waves, you could clip it and so on. In addition, with FastLED’s beatsin8() function, you don’t even need delays at all.

    Reply

    Andrew

    • Dec 11, 2016 - 12:22 PM - hans - Author: Comment Link

      Hi Andrew,

      thank you very much for your input, and you’re right about the ability to optimize this much more. If I’d be writing this just for me, things would look very different. However … the intend is that everybody (as far as possible) can follow all this just fine, or at least with minimal effort. And yes, there is always room for improvements, and I’m very open to that, so please feel free to post modified sources that have been optimized. I’m confident that certain users will definitely be interested. 

      Also keep in mind; I’m trying to target everybody and I have found that explaining a sinus to my 11 year old nephew proved challenging, not to mention that quite a few users have no programming background.

      I would like to invite you though to post optimized alternatives here – It would be welcome for sure. 

      Reply

      hans

  • Dec 17, 2016 - 2:34 PM - gbonsack Comment Link

    Marvelous amount of information – thanks. I’ve bookmarked your site for additional reading.
    I am into light painting photography, using tri-color LEDs for years, with a bank of logic switches to control color. Just read a magazine article about Arduino’s and have gone crazy looking for new light patterns and codes. I have a two part question:
    First, I want to build several light painting props, where I can turn on a “GO” switch and then select one of the switch positions of a 4 or 5 position switch. Should I go with the “HIGH/LOW” logic or put resistors between the 5 positions and push 0, 1.25, 2.5, 3.75 or 5 volts to the input and do voltage logic?
    In either case, what would the: if, then else logic look like, directing the Arduino to run program1 … program5?
    I went to the forum and read imdr5534 logic, but that was for a system generated number and not a selected input.

    Thank you in advance.

    Reply

    gbonsack

    • Dec 19, 2016 - 8:30 AM - hans - Author: Comment Link

      Hello Gbonsack!

      Thank you for the compliment, and … Wow, I had never heard about light painting photography – that looks great! 

      I’d probably go for using several pins and maybe a rotary switch. You’ll need a wire from GND with a resistor to a pin or several pins (see basic diagram here – you’ll find some basic code there as well on how to read a switch/button state), then a wire for each pin to a switch which shorts to +5V. I’d probably consider using a rotary switch so we do not switch multiple switches at the same time.

      Then in code it could look something like this:

      if (firstswitch==high) {
         starteffect1(); } 
      else if (secondswitch==high) {
         starteffect2(); }
      ... etc

      It could be done more elegant of course, but this would probably be an easy start.

      Reply

      hans

      • Dec 19, 2016 - 8:55 AM - gbonsack Comment Link

        Thanks, That’s the way I was leaning, but with only a few weeks of coding, my first test loop was only working for switch position 1 and 2 and not 3, 4 and 5. It may have been a bread board or jumper wire issue too, now that I think of it. Adafruit has an article on using pixel strips, to paint with, search for: Jabberwock.

        Reply

        gbonsack

        • Dec 20, 2016 - 9:07 AM - hans - Author: Comment Link

          I’d go with what feels right for you, especially when you’re just starting with the Arduino.
          You can always try to find more elegant solutions once you get more experienced with Arduino coding – at least that’s how it works for me. This way I get a better feel for what I’m doing as well … 

          I’ll take a looksy and see what Jabberwock stuff I can find (some links I found so far: Overview, and this one). 
          So far I like it 

          Reply

          hans

          • Dec 20, 2016 - 9:10 AM - gbonsack Comment Link

            That’s it. Happy Holiday’s

            gbonsack

          • Dec 20, 2016 - 9:16 AM - hans - Author: Comment Link

            Merry Christmas and a Happy New Year to you too 

            hans

  • Dec 20, 2016 - 3:06 PM - Aldo Comment Link

    Hi Hans!            Could you help me please?

    I want to combine 10 effects in one sketch,  but Effect Bouncing Balls is infinite … ..i don’t know how limit the number of cycles Bouncing Balls?

    merry chirstmas and

    happy new year!!!!!!!!

    Reply

    Aldo

    • Dec 21, 2016 - 10:26 AM - hans - Author: Comment Link

      Hi Aldo,

      several users have been working on combining the effects in one sketch (see also our Arduino Forum).

      The trick for the bouncing balls is found in modifying like #26;

        while (true) {

      This keeps going forever of course. You could modify this to a loop, or a time count.

      Hope this helps 

      Reply

      hans

      • Dec 21, 2016 - 12:27 PM - rompipelotas Comment Link

        thanks a lot!!!     bye..  Hans!!!

        Reply

        rompipelotas

  • Jan 7, 2017 - 8:55 PM - Claire Tompkins Comment Link

    Hi, Hans,

    You helped me a few years ago with a sketch and now I’m back for more. . I’m making a cloud lamp and I’d like to have a lightning effect inside. I have an Arduino Mega and a short strip of WS2812B  NeoPixels. I want the effect to be random, like real lightning. For example, three quick flashes, dark for several seconds, then a slower flash fading up; that kind of thing. I thought I could edit the strobe sketch or the Halloween eyes, but I don’t understand how to use the random function. Would love some help! 

    Thanks,

    Claire

    Reply

    Claire Tompkins

    • Jan 8, 2017 - 2:28 PM - hans - Author: Comment Link

      Hi Claire!

      Welcome back 

      Maybe this will be helpful;

      The function is called as such: 

      Strobe(0xff, 0xff, 0xff, 10, 50, 1000);

      Where the first 3 parameters define the color (0xff),
      The 4th parameter sets the number of flashes (10 flashes),
      The 5th parameter sets the delay between flashes (50 ms),
      and finally the 6th parameter determines how long we’d like to wait after the flashes have been done (1000 ms).

      So this function is responsible for a one time effect.
      In the example: 10 white flashes with 50ms pause between each flash, and once done a 1 second delay (1,000 ms = 1 second).

      Now, since it’s placed in the “void loop() { … }” this function will be called over and over again, with the same parameters. So just a rinse and repeat of the same effect. To add randomness to this we could modify the function call and use the Arduino “random()” function.

      An illustration how we we could use this (can be done much more compact – but this way it’s easier to read and understand):

      In the beginning of the sketch, just before the “void setup {” line, define the following variables:

      byte red = 0xff;
      byte green = 0xff;
      byte blue = 0xff;
      int numberOfFlashes;
      int delayBetweenFlashes;
      int pauseAfterEffect; 

      … and change the “void loop() {” to something like this:

      void loop() { 
        numberOfFlashes=random(10);  // random number between 0 and 10
        delayBetweenFlashes=random(100); // random number between 0 and 100
        pauseAfterEffect=random(1000); // random number between 0 and 1000
        Strobe(red, green, blue, numberOfFlashes, delayBetweenFlashes, pauseAfterEffect);
      }

      Note: the Arduino doesn’t really do random numbers very well, since it always starts with the same “seed”. We can however change the seed by a more random number whenever the sketch starts by adding the “randomSeed()” function to the “void setup() { … }”.

      void setup(){
        // if analog input pin 0 is unconnected, random analog noise will cause the call to randomSeed() to generate
        // different seed numbers each time the sketch runs. randomSeed() will then shuffle the random function.
        randomSeed(analogRead(0));
      }

      Just an idea to add more randomness to the whole thing: make the color brightness intensity random as well:

      void loop() { 
        numberOfFlashes=random(10); // random number between 0 and 10
        delayBetweenFlashes=random(100); // random number between 0 and 100
        pauseAfterEffect=random(1000); // random number between 0 and 1000
        red = random(30, 255); // random number between 30 and 255
        Strobe(red, red, red, numberOfFlashes, delayBetweenFlashes, pauseAfterEffect);
      }

      You might notice that I introduced two things here. First of all “random(x);” produces a random number between zero and x. “random(x,y);” generates a random number between x and y. You might want to use that in the other variables as well, to make sure that a minimum delay is observed.
      The other thing I did is set the color to “red, red, red” – I’m packing a random number between 30 and 255 for the variable red. Since you might want to keep a “white” like color, we would need to have red, green and blue to be the same number. So I’m just recycling the variable for green and blue as well – I hope that doesn’t make it too confusing.

      Hope this helps 

      Reply

      hans

      • Jan 10, 2017 - 10:03 PM - Claire Tompkins Comment Link

        Thanks! But I need some more hand holding, I’m afraid. Are you suggesting editing the Strobe sketch? I added the six suggested lines to the top of the sketch and replaced the void loop section as you wrote. But I don’t know what to do with the other two sections of code, void setup and void loop.
        Claire

        Reply

        Claire Tompkins

        • Jan 12, 2017 - 9:06 AM - hans - Author: Comment Link

          Hi Claire,

          maybe it’s better to start a forum topic – so we can post full size code and such without disrupting the comment section here.
          I already started a topic here

          Reply

          hans

          • Jan 14, 2017 - 11:15 AM - gbonsack Comment Link

            FYI, I pulled the code from the Forum page and pasted into the Arduino editing program, made a the changes for NUM_LEDS and PIN and tried to compile it – got a couple of error messages (240 and 300?). Did a re-type of code and still the same error messages and then I stated to look at the “error lines” and found several referenced lines as blank lines, more online searches and found copy/paste can add hidden code. So if the error referenced line 15, I did a control L and enter 15, moved the cursor to the stated of line 16 and hit back space until the cursor was at the last character in line 14, then “enter”, “enter” and that error line disappeared. After doing this several times, the Forum code worked beautifully, so I started to tweak the code for my “Light Painting” sticks.

            Could find a place to comment on the Forum page, so I’m doing it here.

            Thanks

            gbonsack

          • Jan 14, 2017 - 5:08 PM - hans - Author: Comment Link

            Hi Gbonsack,

            You’ll have to register (free) to be able to post comments in the forum. 
            It’s a little inconvenient, I know, but unfortunately a fully open forum invites spammer and script-kiddies to come pollute the forum with none-sense, trolling, advertising, misleading information, etc. — my sincere apologies that I made it that users need to sign up … 

            Anyhoo; you did indeed catch the issue with the error codes.
            As mentioned below; copy the code, paste it into Notepad, copy all from Notepad, paste it into your Arduino IDE – this should strip all excessive characters.

            Under what operating system did you see this happen and with which browser?
            (can’t reproduce it with Google Chrome on MacOS)

            hans

  • Jan 14, 2017 - 2:08 PM - Peter Bohus Comment Link

    Hello, i am a beginner with WS2812B LED strips with an Arduino nano and I would like to use the KITT effect. I try to use it but I get an error. Are you able to help me please, thank you. The error message is:Arduino: 1.8.1 (Windows 10), Board: “Arduino Nano, ATmega328”

    sketch_jan14c:8: error: stray ‘\302’ in program

      FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

    ^

    sketch_jan14c:8: error: stray ‘\240’ in program

    sketch_jan14c:12: error: stray ‘\302’ in program

      TwinkleRandom(20, 100, false);

    ^

    — LINES DELETED —

    Reply

    Peter Bohus

    • Jan 14, 2017 - 5:02 PM - hans - Author: Comment Link

      Hi Peter,

      first off the friendly request to post large source codes, logs, or other lengthy outputs in the forum 

      Coming back to your issue:
      I suspect you might have copied and pasted the code into the Arduino IDE?
      The “stray ‘\240′” and “stray ‘302’” refer to characters in your code that may not be visible, but do interfere with the code.
      I tried finding some reference for you: this is one at Stack Exchange.

      Now, what I usually do (I assume you’re working under Windows) is copy code, then paste it into Notepad, select everything in Notepad and copy it again. Now excessive characters are gone … now paste it into your code editor and try again … 

      Hope this helps. 

      Reply

      hans

  • Jan 15, 2017 - 6:44 AM - Peter Bohus Comment Link

    Hello,

    I would like to ask you if it is possible (how) to change the colour of the moving strip from red to another colour on the cyclon effect. Also how can I do it so the strips start moving from both sides and bounce like this one but from both sides not just one. So it would look like this:

    ——–> <——–

    <——————>

     ——–> <——–

    Explained:

    From both ends the leds will move towards the other side passing each other in the centre (not bouncing apart) then at the ends they bounce back and pas each other again etc.

    Thanks, I hope you can help me as that would be amazing (I’m only a beginner so need to learn these codes)

    :)

    Thanks Peter

    Reply

    Peter Bohus

    • Jan 15, 2017 - 12:04 PM - hans - Author: Comment Link

      Hi Peter,

      Changing the color of the running LED is easy. You can pass it to the function in the “void()” section.
      For example:

      Red: 

      CylonBounce(0xff, 0, 0, 4, 10, 50);

      Green: 

      CylonBounce(0, 0xff, 0, 4, 10, 50);

      Blue: 

      CylonBounce(0, 0, 0xff, 4, 10, 50);

      The first 3 parameters are hex RGB (red green blue) colors (see also the color picker in this article).

      As for your second question; this is kind-a what the New KITT effect does, just a little more elaborate.
      You’d have to modify this a little bit for the NewKITT() function (so copy the NEW Kitt code and replace the “void NewKITT(…)” function with thsi):

      void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
        OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
        CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
      }

      I have not tested any of these, but I’m confident this will do the trick … 

      Reply

      hans

      • Jan 15, 2017 - 1:28 PM - Peter Bohus Comment Link

        That is kind of what I wanted, but I wanted it to not bounce apart in the middle. Like the Cylon but from both sides so it will start on left and right and go to the opposite sides and then bounce at the end of the strip and bounce back again to the opposite sides instead of bouncing in the middle.

        Thanks Peter

        Reply

        Peter Bohus

      • Jan 16, 2017 - 8:52 AM - hans - Author: Comment Link

        Hi Peter!

        I think I know what you might mean haha … so we have 2 “runners”, one starts on the left and bounce on the right, back the to left where it bounces again to the right etc. In the meanwhile the other one does the exact opposite?

        We could tweak one or the other function together for that;

        void BounceBothWays(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
          for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
            setAll(0,0,0);
            setPixel(i, red/10, green/10, blue/10); setPixel(NUM_LEDS-i, red/10, green/10, blue/10); // opposite side
            for(int j = 1; j <= EyeSize; j++) {
              setPixel(i+j, red, green, blue); setPixel(NUM_LEDS-(i+j), red, green, blue); // opposite side
            }
            setPixel(i+EyeSize+1, red/10, green/10, blue/10); setPixel(NUM_LEDS-(i+EyeSize+1), red/10, green/10, blue/10); // opposite side
            showStrip();
            delay(SpeedDelay);
          }
          delay(ReturnDelay);
        }

        I have not been able to test this though … but it might get you started.
        You’d call it in the void loop.

        void loop() {
          BounceBothWays(0xff, 0x00, 0x00, 8, 10, 50);
        }

        Hope this helps … 

        Reply

        hans

  • Jan 15, 2017 - 7:39 AM - Drax Comment Link

    Hi, i need some help. I’m clueless when it comes to programming so I’m kinda lost.  I have an issue, whatever is meant to fade out and then in to change, is blinking and changing instead. Is my strip faulty, or am i doing something wrong. Using arduino nano clone and ws2812b 5050 led tape (60 led), 
    Arduino nano, ATmega328

    Reply

    Drax

    • Jan 15, 2017 - 11:52 AM - hans - Author: Comment Link

      Hi Drax,

      I’d first see if the LED strand test works, just to make sure Arduino, LEDs and powersupply play nice.
      I have only played with the Uno, and I tend to stay away from clones since they can create all kinds of issues.

      Reply

      hans

      • Jan 15, 2017 - 4:13 PM - Drax Comment Link

        Made a video showing what is wrong here. I that an LED tape issue, arduino issue or power supply issue ?

        Reply

        Drax

        • Jan 16, 2017 - 8:35 AM - hans - Author: Comment Link

          Hi Drax,

          ehm, the link to the video is somehow pointing to this page again … could you repost the link please? 
          Sorry for the inconvenience … 

          Reply

          hans

  • Jan 15, 2017 - 9:52 AM - gbonsack Comment Link

    Hans, Windows 10 and Microsoft Edge gave me the 302 and 240 error messages. As for the Forum, I thought I was logged in, as it showed my IP address, login name.

    Reply

    gbonsack

    • Jan 15, 2017 - 11:50 AM - hans - Author: Comment Link

      Oh boy, yeah … I really cannot recommend Microsoft browsers for any purpose. Rather use something like Google Chrome, Apple Safar, FireFox or Opera.

      Thanks for posting this though, since others might run into the same issue! 

      As for the forum; maybe this is browser related as well – I have not tested Microsoft Edge with my website yet.
      Would you mind checking again? When logged in, you should see (at the bottom of a topic) a text editor to post replies.

      Reply

      hans

  • Jan 15, 2017 - 8:01 PM - Guy-Laurent Comment Link

    Hello Hans,
    First, thank you very much for this superb page. (The best on the web ).
    Difficult to find information on the implementation of “NeoPixel” (Adafruit).

    I am a beginner in programming (Arduino IDE) and I realized an e-textile project (ATtiny85 + 1x LED RGB WS2812B) with one of your script (NeoPixel) that works well.

    The base comes from: “Blinking Halloween Eyes”. (My script not posted as requested).
    But I would like to work with 2-3 colors like: “Fade In and Fade Out Your own Color(s)”.

    Since “Blinking Halloween Eyes”, so I would like to add 2-3 colors and a Fade-in. (Existing Fade-out).
    Currently I come back with another color with function: [setAll(0,0,0);].
    I want to keep the random side for the whole !

    I tried to mix these two scripts unsuccessfully. Can you help me ? Thank you in advance – I would be so happy.
    (If it’s simpler with the “FastLED” Framework. I can also try).

    Greetings from Switzerland  
    PS: My current project uses only one LED RGB, but in the future why not 2-3 LEDs – which would have a different sequence.

    Reply

    Guy-Laurent

    • Jan 16, 2017 - 8:34 AM - hans - Author: Comment Link

      Hello Guy-Laurent!

      First off: thank you for the very nice compliment – that’s always appreciated and definitely a motivator! 
      Thank you so much for observing the code posting request, if you’d like, you can post the code in our Arduino forum.

      I’m not sure I understand what you’d like to accomplish though (sorry – it’s early in the morning here so I probably need more coffee) 
      I guess I’m getting a little confused; do you want a each “eyes” to appear in different colors?
      Or a different color to fade in/out? And you’re using only one LED? or one LED Strip?
      Since I’m sure I can help, I did start this forum topic so we can chat about code and how to implement it. (you’d have to register, but it’s free)

      Reply

      hans

      • Jan 16, 2017 - 10:17 PM - BravoZulu - Author: Comment Link

        Hello Hans,
        Thank you for the message – and your link.

        I am now registered on the forum – but I can not log in ! 
        Tested with Chrome (clear cache) & I.E.11 – Win7Ux64

        Do you have to validate my registration ?

        If there is no more coffee, I will go to sleep 
        See you soon,
        Guy-Laurent

        Reply

        BravoZulu

        • Jan 17, 2017 - 8:58 AM - cam Comment Link

          Hi Guy-Laurent,

          I registered yesterday and had the same issue you have. Seems that admins must approve your account before you can post on the forum.
          I could not create a topic right after registering but this morning it was ok.

          Try again a bit later

          Reply

          cam

          • Jan 17, 2017 - 9:26 AM - hans - Author: Comment Link

            Hi Cam,

            I’m sorry to hear you’re running into issues with the forum (I’m getting pretty fed up with the forum software ).
            Admins do not need to approve your account, but I did notice that on rare occasions a page needs to be reloaded for the text box to appear so you can add or reply to a post. 

            Please let me know if you run into more issues with the forum – I’m already looking for a replacement forum.

            hans

        • Jan 17, 2017 - 9:29 AM - hans - Author: Comment Link

          Hi Guy 

          Yes, coffee is always good 

          I noticed that sometimes the forum is acting up, so I’m already looking into replacing it with another forum.
          Occasionally the user has to reload the page to be able to post a new topic or reply to a topic. It’s quite aggravating since I can’t seem to find a fix for it.

          Would you mind trying to login again? 

          Reply

          hans

          • Jan 17, 2017 - 10:49 AM - BravoZulu Comment Link

            Hello Hans,
            After many tests yesterday – I’m now logged 
            (Yesterday by selecting a link in the history of the browser, I was logged – but only on this page of course – Then by clicking on the link of the other subject I was losing the log-in).

            The problem: when you do the log-in, the Menu at the top right is always as if you were not logged in. (You do not see the user – [User Menu]).
            It seems that at this moment, by making a refresh of page one becomes logged !
            Then I repeatedly got the message (Top of Chrome): “WebGL encountered a problem” – [Ignore]  [Refresh].
            (Never seen this message before with other sites).
            To be continued…

            So, I will continue on the page: blinking-halloween-eyes-with-different-colors
            Guy-Laurent

            BravoZulu

          • Jan 17, 2017 - 1:01 PM - BravoZulu Comment Link

            « Houston, we have a problem »  

            After log-in according to the trick: refresh the page, I have posted 3 times without success !
            The image I wanted to attach was too big !? (Max 4MB).
            I went from 3.6MB to 1.5MB then 960KB – Every time with the error message (Chrome):

            Request Entity Too Large:
            The requested resource
            /forums/topic/blinking-halloween-eyes-with-different-colors/
            does not allow request data with GET requests, or the amount of data provided in the request exceeds the capacity limit.
            Additionally, a 413 Request Entity Too Large error was encountered while trying to use an ErrorDocument to handle the request.

            I attempted to send the image alone (960KB) with the same error.
            My Post is now Online – but no picture  

            To be continued…
            Guy-Laurent

            BravoZulu

          • Jan 17, 2017 - 1:26 PM - BravoZulu Comment Link

            Bingo !
            With an image (alone) of 86KB.

            BravoZulu

          • Jan 18, 2017 - 9:45 AM - hans - Author: Comment Link

            Hi Guy!

            Oh wow, I better check my settings then … I did set it to 4Mb max, so the images should have worked, and I have never seen this error message before.

            Just verified the settings, both PHP and bbPress are set to 4Mb per file max, and max 4 files per post. I’ll try uploading something myself and see what that does …

            Again apologies for the problems you’re running into and thanks for sticking around 

            hans

          • Jan 18, 2017 - 9:54 AM - hans - Author: Comment Link

            OK, tested it as admin and as a participant (forum roles) and both were able to upload a 2Mb picture.
            I’m running Google Chrome on macOS Sierra.

            I did change some settings in bbPress, maybe this helps. Would you mind trying again?
            (I’ll continue this conversation there haha)

            hans

          • Jan 20, 2017 - 7:19 PM - BravoZulu Comment Link

            Hello Hans,

            I think you saw, I was able to download 2 images (2.7MB and 450KB) without problems. (Chrome Win7Ux64).
            Your changes seem to be conclusive  
            PS: I can now read: “Your account has the ability to upload any attachment regardless of size and type.”

            BravoZulu

  • Jan 16, 2017 - 10:58 AM - gbonsack Comment Link

    I got the comment window this AM??? System re-booted over night??? Flip-A-Coin

    Reply

    gbonsack

    • Jan 16, 2017 - 1:04 PM - hans - Author: Comment Link

      Hi Gbonsack …

      ehm, you mean your system rebooted? Not sure what you’re referring to 
      (I need more coffee – that’s for sure )

      Reply

      hans

  • Jan 16, 2017 - 5:38 PM - cam Comment Link

    Hi,

    I wanted to thank you for all these examples, it made me want to have fun with those LEDs. I actually had a DAC project ongoing and I’m using these ideas (and the way they’re coded since I’m in uncharted territory here).

    I actually have a problem but since I modified the code to fit my plans I’m going post my code on the forum so anyone can help me understand what’s wrong :D

    Thanks again for the ideas and the very well explained code there is on this page, it is very educational.

    Reply

    cam

    • Jan 16, 2017 - 6:49 PM - cam Comment Link

      I registered but couldn’t create topic so I’ll explain my problem here, code is there.

      It seems that dutch people inspired me on this project since my DAC board is based on Doede Douma DDDAC with differences on components (all SMD to gain size). an output buffer has been added as well as a FIFO buffer followed by a reclock board.

      First, context. I’m making myself a DAC and I was looking into VHDL and PWM for a little while but as I expected, last time I used VHDL was in school more than 10 years ago and I suck a lot at it! I have a bit better knowledge of C.

      Back to subject of interest. I found this article which made me hopeful (almost a better man!). My idea of the result goes through phases (I used switch/case ).

      1st phase: Start-up lighting to actually signify to user it started. I used fade in/out code, I only modified the brightness increasing with sine wave instead of linear.
      2nd phase: RaspberryPi starts and look for a connection to my NAS. I used twinkle effect.
      3rd phase: When NAS is found, the RaspberryPi updates its output and my arduino goes back to almost the same fade in/out as in phase 1 except it doesn’t go back to LEDs off but stays to 50% (I don’t want too much light and I like how it looks to go high and a little back down).
      4th phase: Steady lighting at defined brightness. If connection to NAS is lost, it goes back to phase 2.

      Seems nice but it only half works. phase 1 and 2 works perfectly fine but when I connect my wire to simulate the input from the RaspberryPi it goes crazy. It’s like the switch/case is broken and I have all code executed at the same time and it looks badI could make a video to clear things up if required. I’ve got to mention I don’t arduino but a smaller Adafruit Pro Trinket with 10 LEDs.

      Reply

      cam

  • Jan 19, 2017 - 9:09 AM - Warren Richardson Comment Link

    You have saved me so much time….Tons of love.

    Reply

    Warren Richardson

    • Jan 19, 2017 - 10:22 AM - hans - Author: Comment Link

      Hi Warren!

      Thanks for taking the time to post a “Thank you” … glad to hear you’ve enjoyed this article! 

      Reply

      hans

  • Jan 23, 2017 - 10:50 AM - gbonsack Comment Link

    I just uploaded, to the Forum, my modified Button Cycle .ino, where every time I press a normally open switch, the sketch jumps to the next loop (case) segment and does a different light pattern sequence. The problem is if I am doing a photography workshop and the people want loop #5 repeated, I have to power down and restart at loop #1, pressing the button time and again until I get to loop #5 (each loop creates a 35 second light show). I have tried to modify that sketch to take a keypad input of 5 to jump to that case (Keypad_Test), but I have two (2) lines that keep giving me error messages. I have re-typed those lines and many other lines above and below the error lines, plus lines in the define section and have cleared many other error messages (I’m using Windows 10) and from previous posts see where I should have possibly saved the code to Notepad and then copied it into IDE. If that is the answer, then so be it, but if I am doing something stupid, then tell me – thanks. 

    Reply

    gbonsack

    • Jan 24, 2017 - 11:33 AM - hans - Author: Comment Link

      I just replied with a suggestion the forum.
      Others; please feel free to join the conversation with better and/or smarted solutions! 

      Reply

      hans

    • Feb 5, 2017 - 11:50 AM - gbonsack Comment Link

      I solved the issue, with the 2 lines of code that were giving me error messages, it seems that “Fat Fingers” had creeped  in and I had an extra character in the define line. I now have a working 3 X 4 matrix keypad., where I can press any one of the 12 keys and that case/loop runs. A sample video has been posted on YouTube https://youtu.be/t14OyY58YNY and I’ll post the full code on the Forum page https://www.tweaking4all.com/forums/topic/lightning-effect/

      Hans, thanks for the comments, to get me thinking correctly.

      Reply

      gbonsack

  • Feb 7, 2017 - 9:38 AM - Stan Comment Link

    Sorry. I now to coding and i am zero. Of course i have a long road to go and for now i m just trying to het the logic. I just want to ask this ; i see j and k and i integers. I didnt get what are these because i dont see that we define these letters as integer names in void setup. Are they predefined in library or what? Thanks. Sorry for my english. I m not native talker. So i guess u also understand why its hard to understand that kind of articles for me.

    Reply

    Stan

    • Feb 7, 2017 - 9:53 AM - hans - Author: Comment Link

      Hi Stan,

      these variables are defined on the fly. For example:

      for(int k = 0; k < 256; k++) { ...

      This says: start a loop where we count 0-256, by using the integer variable k. See the “int” in front of it? Here we define “k” as an integer (see also the for-loop section of my mine course).

      The definition of variables is done based their scope.

      So for example, a variable that needs to be available everywhere, is defined way at the beginning of your code.
      If the variable is only needed in for example the “setup()” function, then we define it only there, ideally in the beginning of the code.
      If however, the variable is only need briefly, for example for counting in a loop, then we can choose to define it right there (as seen in the example).

      Reply

      hans

      • Feb 7, 2017 - 9:59 AM - Stan Comment Link

        Yes Hans i see int goes for integer but i disnt know we Define k in here. I was thinking we Want k to do something in ur code. So its a Define code, not a Do code. Umm okay. Thanks for ur very fast reply that was so nice of u. I will dig on that in my mind. I m a newbee. Thanks again. I guess i need another article that teachea Coding from zero and the logics of it. 

        Reply

        Stan

      • Feb 7, 2017 - 10:07 AM - hans - Author: Comment Link

        No worries, we all had to start at some point in time … 
        This might be helpful to get started: Arduino Programming for Beginners.
        I wrote it for those with no programming experience, so maybe it’s helpful for you as well.
        Enjoy! And feel free to ask question if you have any (either under the related article or in the forum).

        Reply

        hans

        • Feb 7, 2017 - 10:13 AM - Stan Comment Link

          Wow. This cant be real. I email and wrote so messages on some websites and i wait for days long but was no reply. And you show me road to start and tell me to feel free to ask if i have some to. My friend i would like to give a handshake to u. I m so happy to hear this friensly sentences from u. I do thank you. Now i have more energy to sit and learn this. (I am web&graphic designer and in love with electronics from childhood times and i want to combine them in my interior design lighting projects). Peace..

          Reply

          Stan

          • Feb 7, 2017 - 11:02 AM - gbonsack Comment Link

            Hi Stan,

            I got my Arduino unit mid-November and beat my head against the wall too. My best advise is think of coding as a good book – Introduction, Table of Content and the individual chapter or chapters.

            What I wanted to do was create a “Light Painting Stick” for photography, where I could press one of the keys, on a 3 X 4 keypad and have that sub-loop/sketch run. With a few comments from Hans, it all came together for me and if you read the above Feb. 5 post, there is a link to the finished code – enjoy this site.

            gbonsack

          • Feb 7, 2017 - 11:09 AM - Stan Comment Link

            Thanks Gronsack. . I ve seen a lot on light paintings and its a realy awesome type of usage of leds. I will definitely check that post and the code

            Stan

        • Feb 7, 2017 - 10:16 AM - hans - Author: Comment Link

          You’re most welcome – I try to answer as fast as I can … sometimes that’s right away, sometimes it’s a day later (timezone difference and of course sometimes my daytime job interferes ).

          I’m always happy to help! 

          Reply

          hans

  • Feb 10, 2017 - 12:31 AM - candy Comment Link

    hello,

    i want to make a rainbow code of the color wipe. i mean that the color stable to show out like a rainbow in 16 LED lights. i dont want to make a rainbow run. can u suggest for me? thank you very much.

    candy

    Reply

    candy

    • Feb 10, 2017 - 8:26 AM - Stan Comment Link

      Sorry i dont understand what is color wipe

      Reply

      Stan

  • Feb 10, 2017 - 8:44 AM - gbonsack Comment Link

    candy,

    If I understand correctly, you want LED ‘0’ (first LED) to be red and the last LED to be violet? If so consider defining each of the 16 LED’s like this (you need to enter color code as desired). This is copied from another program, so verbiage may have to be changed to suit. Have to run for an appointment, but will check later today.

    // Put color values in arrays

    long invader1a[] =
    {
    0x008000, 0x000000, 0x000000,0x000000,0x000000,0x000000,0x000000, 0x008000,
    0x008000, 0xFFFF00, 0x0000FF, 0xFFFF00, 0xFFFF00, 0x0000FF, 0xFFFF00, 0x008000,
    0x008000, 0x000000, 0xFFFF00, 0x800080, 0x800080, 0xFFFF00, 0x000000, 0x008000,
    0x000000, 0x000000, 0x000000, 0xFF0000, 0xFF0000, 0x000000, 0x000000, 0x000000
    };

    long invader1b[] =
    {
    0x000000, 0x000000, 0x0000FF, 0xFFFF00, 0xFFFF00, 0x0000FF, 0x000000, 0x000000,
    0x000000, 0x008000, 0xFFFF00, 0x800080, 0x800080, 0xFFFF00, 0x008000, 0x000000,
    0x008000, 0x000000, 0x000000, 0xFFFF00, 0xFFFF00, 0x000000, 0x000000, 0x008000,
    0x000000, 0x008000, 0x000000, 0xFF0000, 0xFF0000, 0x000000, 0x008000, 0x000000
    };

    Reply

    gbonsack

    • Feb 10, 2017 - 9:07 AM - hans - Author: Comment Link

      Awesome guys – thanks for chiming in! 

      If we indeed mean a static rainbow, then that code would work, and I’m sure there would be a smart calculation for it as well but using array like that is easier to understand.

      Reply

      hans

    • Feb 10, 2017 - 11:36 AM - candy Comment Link

      thank you very much

      yes, i want LED ‘0’ (first LED) to be red and the last LED to be violet which show out at the same time in 16 LED’s. But the colors are not run in the 16 LED

      But the above code, where can i put it?

      Otherwise, i want to adjust the code. when i load the program to my arduino, my other function I2C display can not show out out and detect sensor must delay to read the data, can you give me some suggest?

      Reply

      candy

      • Feb 10, 2017 - 5:36 PM - gbonsack Comment Link

        I just wrote this:

        #include <Adafruit_NeoPixel.h>

        #define PIN 6

        Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

        // I wrote this using just an 8 LED strip, so change 8 above to 16 and double the lines below

        void setup() {

        strip.begin();

        strip.show();

        // Initialize all pixels to ‘off’

        }

        void loop ()

        {

        strip.setPixelColor(0,125, 0, 0);

        strip.setPixelColor(1, 80, 45, 0);

        strip.setPixelColor(2, 64, 64, 0);

        strip.setPixelColor(3, 0, 125, 0);

        strip.setPixelColor(4, 0, 64, 64);

        strip.setPixelColor(5, 0, 0, 125);

        strip.setPixelColor(6, 50, 0, 75);

        strip.setPixelColor(7, 40, 40, 40);

        // (led position, amount red, green, blue) I use lower numbers to reduce brightness

        strip.show();

        }

        Reply

        gbonsack

        • Feb 10, 2017 - 10:04 PM - candy Comment Link

          thank you very much, Gbonsack

          Reply

          candy

          • Feb 10, 2017 - 10:09 PM - candy Comment Link

            i try it that is good result for me. thank you for your time. thank you very much….

            candy

        • Feb 11, 2017 - 11:52 AM - hans - Author: Comment Link

          That would work very well of course! Thanks Gbonsack! 

          Candy; you’ll just have to expand this to 16 LEDs – you can use the color picker and split the hexadecimal number into 3 sections. For example B5FF8A would become (the first parameter – 1 – is the LED number):

          strip.setPixelColor(1, 0xB5, 0xFF, 0x8A);

          So B5FF8A becomes: B5, FF, and 8A. to let the Arduino know this is not a normal number, but a hexadecimal number, add “0x” (zero-X) in front of each of the numbers (this would save you from having to think too much about hexadecimal number and convert them).

          Reply

          hans

          • Apr 2, 2017 - 7:57 AM - candy Comment Link

            thank you Hans

            BUt i have another problem to come out.. plz help.

            candy

          • Apr 2, 2017 - 4:02 PM - hans - Author: Comment Link

            Hi Candy,

            I’m sorry that I had to remove all the code you posted, but this became a little too much for the comment section.
            Could you place your question in our Arduino forum please?
            I’d be happy to take a look and see where I can help. But with long codes being posted here, other users would have to scrolls for days to find something.

            hans

    • Feb 10, 2017 - 2:34 PM - hans - Author: Comment Link

      Hi Candy,

      I do not have my Arduino stuff nearby, but you could try this modified code:

      void loop() {
        rainbowCycle();
      }
      void rainbowCycle() {
        byte *c;
        uint16_t i, j;
          for(i=0; i< NUM_LEDS; i++) {
          c=Wheel(((i * 256 / NUM_LEDS)) & 255);
            setPixel(i, *c, *(c+1), *(c+2));
          }
        showStrip();
      }
      byte * Wheel(byte WheelPos) {
        static byte c[3];
        
        if(WheelPos < 85) {
         c[0]=WheelPos * 3;
         c[1]=255 - WheelPos * 3;
         c[2]=0;
        } else if(WheelPos < 170) {
         WheelPos -= 85;
         c[0]=255 - WheelPos * 3;
         c[1]=0;
         c[2]=WheelPos * 3;
        } else {
         WheelPos -= 170;
         c[0]=0;
         c[1]=WheelPos * 3;
         c[2]=255 - WheelPos * 3;
        }
        return c;
      }

      Not sure if the colors will appears as desired …

      The code would replace this section:

      // *** REPLACE FROM HERE ***
      void loop() { 
       // ---> here we call the effect function <---
      }
      // ---> here we define the effect function <---
      // *** REPLACE TO HERE ***

      Your next question is to combine the code with controlling a display and reading sensors. This makes things a little bit more complicated and we’d need to see the code for those peripherals. 
      Since this might become a rather longer topic, I recommend starting a topic in our Arduino Forum.

      Reply

      hans

      • Feb 10, 2017 - 10:01 PM - candy Comment Link

        thank you very much, Hans.

        Reply

        candy

      • Nov 7, 2019 - 2:07 AM - Trollo_meo Comment Link

         Hello Hans

        I tried myself at the rainbowcycle code.

        In the video it looks great.

        But I don’t get it….

        I’m receiving always the error message:

        21: error: ‘setPixel’ was not declared in this scope

               setPixel(i, *c, *(c+1), *(c+2));

                                             ^

        23: error: ‘showStrip’ was not declared in this scope

           showStrip();

                     ^

        exit status 1

        ‘setPixel’ was not declared in this scope

        This report would have more information with

        “Show verbose output during compilation”

        option enabled in File -> Preferences.

        I’m an apprentince and I tried to do an LED Matrix as a project with the arduino Nano.

        I’m trying to get a few programms on my arduino and switch between those with some switches.

        I really like the rainbow effect so I decided to do the rainbowcycle too

        as I said and mentioned I’m getting the same error message again and again…

        Do u have some extra files where u declared respective defined these functions?

        Thanks already

        Reply

        Trollo_meo

        • Nov 7, 2019 - 2:55 AM - hans - Author: Comment Link

          Hi Trollo_meo,

          since I do not see the entire sketch you’re using (and pretty please do not post it here – the forum is the place to post large pieces of code), I can only guess that you didn’t copy the framework.
          See this section: FastLED Framework.

          The idea was to have a framework depending on the library you’d like to use – FastLED (recommended) or NeoPixel.
          The “framework” is the base for all sketches, and where indicated you have to paste the effect code into this framework code.

          Hope this helps,

          Hans

          Reply

          hans

  • Feb 17, 2017 - 9:36 AM - gbonsack Comment Link

    Here is a link to my latest Arduino driven Light Stick video:

    https://youtu.be/nA8IT59nD00

    I find cutting the output of the LED’s to 25 to 50% gives me better color saturation and doesn’t burn out the video colors.

    I now have the 121 keypad code working, as well as the multiple position and pushbutton advance switch code. Thanks again to you Hans, for your direction and tips.

    Reply

    gbonsack

    • Feb 18, 2017 - 11:00 AM - hans - Author: Comment Link

      That’s just awesome! I probably should dig into this topic as well – looks really great! 
      Thanks for sharing! 

      Reply

      hans

  • Mar 9, 2017 - 2:19 PM - Ben Linsenmeyer Comment Link

    Hi there, I’m very new to all of this. I have completed the strand test and uploaded a couple effects. My question is: if I want to make a standalone strip that cycles through effects with the push of a button, where would I begin? As in, I want to give the whole assembly a power cord, and just use a button to cycle through effects, how would I do so?

    Reply

    Ben Linsenmeyer

    • Mar 9, 2017 - 3:14 PM - hans - Author: Comment Link

      Hi Ben,

      cycling through effects has been requested a few times (which makes me want to write an article about it, but simple do not seem to get to actually finding time to do it). A few users have been working on the same question in the Arduino Forum – that would be a great starting point.

      Feel free to join a conversation there or post your own question.

      Reply

      hans

      • Mar 10, 2017 - 9:41 AM - gbonsack Comment Link

        Ben, thanks to a few comments from Hans, I have created several different light painting sticks, using the Arduino Uno Board and either a 12 button keypad, a 5 position switch or a normally open push button (9 sub-sketches). Sample video’s can be seem on my YouTube page “Gerald Bonsack”. I have found that as the 9V battery gets weak, the Arduino wants to do it own thing and not follow my written code. I have posted one or two of the .ino files, on the Forum page and will post others, if requested. For the 5 position switch, I have the 10k resistor between the ground and the common connection between the 5V supply and the switch – output from the switch goes to INPUT PINS, on the board. Since I started playing with the Arduino only a couple of months ago, my code my not be pretty, but it works.

        Reply

        gbonsack

  • Mar 10, 2017 - 11:46 AM - Marc Johnston - Author: Comment Link

    Hello!  I am trying out these sketches using an Adafruit Trinket as my microcontroller.  For some reason, no matter if I try the Neopixel library, or the Fast LED library, all I am getting when I upload any sketch, say the Fire sketch, is just all white LEDs.  The Neopixel sketches from Adafruit work fine.  Any ideas?

    Reply

    Marc Johnston

    • Mar 11, 2017 - 4:03 PM - hans - Author: Comment Link

      Hi Marc,

      ehm, I’m not familiar with the AdaFruit Trinket. As far as I can read from the specs, there is a 3V and a 5V version – so it might be related to that, since the LEDs might expect 5V for their data, then again, you said that the NeoPixel examples do work.

      The next thing might be in the initialization – verify that with the ones used in the NeoPixel examples:

      Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

      Also make sure you use the same NeoPixel library (but you probably already do this).

      Since NeoPixel is the only one you want to use (for testing), you could narrow down the code to:

      #include <Adafruit_NeoPixel.h>
      #define PIN 6
      #define NUM_LEDS 60
      // Parameter 1 = number of pixels in strip
      // Parameter 2 = pin number (most are valid)
      // Parameter 3 = pixel type flags, add together as needed:
      // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
      // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
      // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
      // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
      Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
      void setup() {
        strip.begin();
        strip.show(); // Initialize all pixels to 'off'
      }
      // *** REPLACE FROM HERE ***
      void loop() { 
       // ---> here we call the effect function <---
      } // *** REPLACE TO HERE ***
      void showStrip() {
         strip.show();
      }
      void setPixel(int Pixel, byte red, byte green, byte blue) {
         strip.setPixelColor(Pixel, strip.Color(red, green, blue));
      }
      void setAll(byte red, byte green, byte blue) {
        for(int i = 0; i < NUM_LEDS; i++ ) {
          setPixel(i, red, green, blue); 
        }
        showStrip();
      }

      Reply

      hans

      • Mar 11, 2017 - 6:15 PM - Marc Johnston Comment Link

        Hans, 

        Thanks for the reply.  I will say upfront, that I am a Arduino newbie.  However, using the code you posted gave me the white LEDs again.  I compared that code to a working Neo Pixel sketch, and noticed some differences that pertain to the Trinket.  I modified the code with those bits, and now when I run it, all the LEDs go black.  Here is the modified code:

        #include <Adafruit_NeoPixel.h>
        #ifdef __AVR__
          #include <avr/power.h>
        #endif
        #define PIN 0
        #define NUM_LEDS 60
        // Parameter 1 = number of pixels in strip
        // Parameter 2 = pin number (most are valid)
        // Parameter 3 = pixel type flags, add together as needed:
        // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
        // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
        // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
        // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
        Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
        void setup() { 
          // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
          #if defined (__AVR_ATtiny85__)
            if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
          #endif
          // End of trinket special code
          
          strip.begin();
          strip.show(); // Initialize all pixels to 'off'
        }
        // *** REPLACE FROM HERE ***
        void loop() { 
         // ---> here we call the effect function <---
        }
        // *** REPLACE TO HERE ***
        void showStrip() {
           strip.show();
        }
        void setPixel(int Pixel, byte red, byte green, byte blue) {
           strip.setPixelColor(Pixel, strip.Color(red, green, blue));
        }
        void setAll(byte red, byte green, byte blue) {
          for(int i = 0; i < NUM_LEDS; i++ ) {
            setPixel(i, red, green, blue); 
          }
          showStrip();
        }

        Reply

        Marc Johnston

        • Mar 12, 2017 - 5:39 PM - hans - Author: Comment Link

          Hi Marc,

          no worries, we all had to start at some point right? 
          Hey! You caught the same difference I did! 

          This code would indeed not do much since you didn’t include an effect, but I think you’re getting closer!
          Replace this code with the effect you’d like to use (unless you already did that):

          // *** REPLACE FROM HERE ***
          void loop() { 
           // ---> here we call the effect function <---
          }
          // *** REPLACE TO HERE ***

          For example with:

          void loop() {
            rainbowCycle(20);
          }
          void rainbowCycle(int SpeedDelay) {
            byte *c;
            uint16_t i, j;
            for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
              for(i=0; i< NUM_LEDS; i++) {
                c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
                setPixel(i, *c, *(c+1), *(c+2));
              }
              showStrip();
              delay(SpeedDelay);
            }
          }
          byte * Wheel(byte WheelPos) {
            static byte c[3];
            
            if(WheelPos < 85) {
             c[0]=WheelPos * 3;
             c[1]=255 - WheelPos * 3;
             c[2]=0;
            } else if(WheelPos < 170) {
             WheelPos -= 85;
             c[0]=255 - WheelPos * 3;
             c[1]=0;
             c[2]=WheelPos * 3;
            } else {
             WheelPos -= 170;
             c[0]=0;
             c[1]=WheelPos * 3;
             c[2]=255 - WheelPos * 3;
            }
            return c;
          }
          Reply

          hans

  • Mar 11, 2017 - 6:20 PM - Marc Johnston Comment Link

    And also, here is a working sketch from Adafruit:

    #include <Adafruit_NeoPixel.h>
    #ifdef __AVR__
      #include <avr/power.h>
    #endif
    #define PIN 0
    // Parameter 1 = number of pixels in strip
    // Parameter 2 = Arduino pin number (most are valid)
    // Parameter 3 = pixel type flags, add together as needed:
    // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
    // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
    // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
    // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
    // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
    // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
    // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
    // and minimize distance between Arduino and first pixel. Avoid connecting
    // on a live circuit...if you must, connect GND first.
    void setup() {
      // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
      #if defined (__AVR_ATtiny85__)
        if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
      #endif
      // End of trinket special code

      strip.begin();
      strip.show(); // Initialize all pixels to 'off'
    }
    void loop() {
      // Some example procedures showing how to display to the pixels:
     

      rainbowCycle(5);
     
    }

    // Slightly different, this makes the rainbow equally distributed throughout
    void rainbowCycle(uint8_t wait) {
      uint16_t i, j;
      for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
        for(i=0; i< strip.numPixels(); i++) {
          strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
        }
        strip.show();
        delay(wait);
      }
    }


    // Input a value 0 to 255 to get a color value.
    // The colours are a transition r - g - b - back to r.
    uint32_t Wheel(byte WheelPos) {
      WheelPos = 255 - WheelPos;
      if(WheelPos < 85) {
        return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
      }
      if(WheelPos < 170) {
        WheelPos -= 85;
        return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
      }
      WheelPos -= 170;
      return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
    }
    Reply

    Marc Johnston

    • Mar 12, 2017 - 5:36 PM - hans - Author: Comment Link

      Hi Marc,

      the only exceptional things I see in this working code is:

      #ifdef __AVR__
        #include <avr/power.h>
      #endif
      ...
        #if defined (__AVR_ATtiny85__)
          if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
        #endif

      I’d assume you have to bring that over to the demo code from this article as well, which would make it like so (note: your code says PIN 0!):
      (I hope I got all the differences, and this would be the “base” code of course – just didn’t want to post very lengthy code, that would be better in the forum, if we want to continue the topic)

      Hope this helps 

      #include <Adafruit_NeoPixel.h>
      #ifdef __AVR__
        #include <avr/power.h>
      #endif
      #define PIN 6
      #define NUM_LEDS 60
      // Parameter 1 = number of pixels in strip
      // Parameter 2 = pin number (most are valid)
      // Parameter 3 = pixel type flags, add together as needed:
      // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
      // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
      // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
      // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
      // Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
      Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
      void setup() {
        // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
        #if defined (__AVR_ATtiny85__)
          if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
        #endif
        // End of trinket special code
        strip.begin();
        strip.show(); // Initialize all pixels to 'off'
      }
      // *** REPLACE FROM HERE ***
      void loop() { 
       // ---> here we call the effect function <---
      }
      // ---> here we define the effect function <---
      // *** REPLACE TO HERE ***
      void showStrip() {
       #ifdef ADAFRUIT_NEOPIXEL_H 
         // NeoPixel
         strip.show();
       #endif
       #ifndef ADAFRUIT_NEOPIXEL_H
         // FastLED
         FastLED.show();
       #endif
      }
      void setPixel(int Pixel, byte red, byte green, byte blue) {
       #ifdef ADAFRUIT_NEOPIXEL_H 
         // NeoPixel
         strip.setPixelColor(Pixel, strip.Color(red, green, blue));
       #endif
       #ifndef ADAFRUIT_NEOPIXEL_H 
         // FastLED
         leds[Pixel].r = red;
         leds[Pixel].g = green;
         leds[Pixel].b = blue;
       #endif
      }
      void setAll(byte red, byte green, byte blue) {
        for(int i = 0; i < NUM_LEDS; i++ ) {
          setPixel(i, red, green, blue); 
        }
        showStrip();
      }
      Reply

      hans

      • Mar 14, 2017 - 8:09 AM - Marc Johnston - Author: Comment Link

        Thanks for all the help Hans.  I’ll look back into it once I get another Trinket in.  

        My original intent was to use the Neopixels to fix the lighting in a friends jukebox.  Most of the lighting effects on it were made by using fluorescent tubes, and color wheels.  The color wheels have long since quit working, and are expensive to replace.   I like the fire effect example here, but as I wasn’t able to get it working (yet), so we went with another fire effect I found @ Adafruit.  Anyways, the end result looks much better than I anticipated.  We ended up using two of the Neopixel rings for the “ends” of the top of the jukeboxe, a strip behind the  “compact disc” area, and two strips going verticle up the leg areas (that’s where the fire is).  I still think the fire example here will look better, and once I figure it out, I can easily upload it.

        Here is a short video we made:

        https://www.youtube.com/watch?v=bqiyCwOSPgQ

        Reply

        Marc Johnston

        • Mar 14, 2017 - 9:47 AM - Spike Comment Link

          Very nice results mate, the Jukebox looks great.

          I usually use the nano for my small lighting projects, though I also relied on a lot of great help from Hans.

          Here’s Christmas decoration I 3D printed and lit up with a nano and some ws2812’s 

          https://youtu.be/Z6lp8Dd5w5w

          Reply

          Spike

          • Mar 14, 2017 - 1:21 PM - hans - Author: Comment Link

            Awesome Spike! 

            What brand/model 3D printer do you use?

            hans

          • Mar 14, 2017 - 2:16 PM - Marc Johnston - Author: Comment Link

            That is very nice!  I think I may order me a Nano instead of a Trinket.  It seems to be a bit more powerful, and not much bigger.

            Marc Johnston

        • Mar 14, 2017 - 1:20 PM - hans - Author: Comment Link

          Hi Marc!

          Thanks for the video – that looks awesome! 

          The fire effect would indeed be very cool for this purpose!

          Reply

          hans

          • Mar 14, 2017 - 2:57 PM - Spike Comment Link

            Hi Hans, Thank you, but it’s all down to your help, it wouldn’t be so good without it.

            That was printed on a version of the i3 that I built myself. I now have an Original Prusa i3 MK2.

            Spike

          • Mar 14, 2017 - 3:09 PM - Spike Comment Link

            Hi Marc, Thank you, I got mine from a UK ebay seller who was very quick to dispatch and with comms.

            The nano has served me well for a lot of LED projects, including a 30×15 matrix https://youtu.be/oiXbXCQdf8c

            Spike

          • Mar 15, 2017 - 8:46 AM - hans - Author: Comment Link

            Oh Wow! I like the matrix! Very cool!

            Yeah I dabbled for a bit with 3D printers, and have to say that I’m probably not patient/accurate enough to work with 3D printers (LeapFrog) just yet haha …  Maybe one of these days I’ll pick it up again.

            hans

          • Mar 21, 2017 - 8:11 AM - Marc Johnston - Author: Comment Link

            Well, I ordered a bunch of Nanos, and have been playing around with them.  All the sketches work fine in them, so I think I’ll use the Trinket for something else.  I appreciate everyone’s help!

            Marc Johnston

        • Mar 21, 2017 - 8:41 AM - Spike Comment Link

          You’re very welcome mate. Glad they are working well for you.

          Reply

          Spike

  • Mar 13, 2017 - 10:52 AM - Bret - Author: Comment Link

    I just wanted to thank you for the code examples!

    Reply

    Bret

    • Mar 13, 2017 - 11:05 AM - hans - Author: Comment Link

      Thanks Bret for taking the time and effort to post a Thank-You — it’s much appreciated! 

      Reply

      hans

  • Mar 14, 2017 - 1:34 AM - Prasanna K Comment Link

    Thank you for sharing the code and beautiful videos with clear details!!!

    Reply

    Prasanna K

    • Mar 14, 2017 - 9:48 AM - hans - Author: Comment Link

      Hi Prasanna!

      Thank you very much for the compliment and for taking the time to post a “Thank you” – it’s very much appreciated! 

      Reply

      hans

  • Mar 15, 2017 - 12:37 AM - Steve Doll Comment Link

    Trying to figure out how to reverse the direction of the running lights code. Any help is appreciated!

    Reply

    Steve Doll

    • Mar 15, 2017 - 8:52 AM - hans - Author: Comment Link

      If you like to have the LEDs run into the opposite direction, just:

      void loop() {
        RunningLights(0xff,0xff,0x00, 50);
      }
      void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
        int Position=0;
        
        for(int i=(NUM_LEDS*2)-1; i>=0; i--) // <-- opposite direction
        {
            Position++; // = 0; //Position + Rate;
            for(int i=0; i<NUM_LEDS; i++) {
              setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                         ((sin(i+Position) * 127 + 128)/255)*green,
                         ((sin(i+Position) * 127 + 128)/255)*blue);
            }
            
            showStrip();
            delay(WaveDelay);
        }
      }

      Is this what you’re looking for?

      Reply

      hans

      • Mar 15, 2017 - 10:54 AM - Steve Doll Comment Link

        Doesnt seem to change the direction

        Reply

        Steve Doll

      • Mar 15, 2017 - 11:00 AM - hans - Author: Comment Link

        Doh, I modified the wrong for-loop … I should drink more coffee before replying hahah …  

        void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
          int Position=0;
          
          for(int i=0; i<NUM_LEDS*2; i++)
          {
              Position++; // = 0; //Position + Rate;
              for(int i=NUM_LEDS-1; i<=0; i--) {   // <-- changed this
                setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                           ((sin(i+Position) * 127 + 128)/255)*green,
                           ((sin(i+Position) * 127 + 128)/255)*blue);
              }
              
              showStrip();
              delay(WaveDelay);
          }
        }

        I’m sorry – I do not have my Arduino and LEDs anywhere near me, so I cannot test …

        Reply

        hans

        • Mar 15, 2017 - 11:47 AM - Steve Doll Comment Link

          Appreciate the help, unfortunately that makes the LEDs not work at all

          Reply

          Steve Doll

        • Mar 16, 2017 - 9:11 AM - hans - Author: Comment Link

          I guess I’ll have to find an Arduino + LED strip to do some testing … 

          Reply

          hans

          • May 5, 2020 - 9:31 PM - Gizmo Props - Author: Comment Link

            One last tweak needed to get the lights to run in reverse, setting the Position to the end and decreasing it:

             void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
              int Position=NUM_LEDS;  // this also needs to start high and decrease
              
              for(int j=(NUM_LEDS*2)-1; j>=0; j--) // this may work
              {
                  Position--; // = 0; //Position + Rate;  // use -- to decrease the position instead of increase
                  for(int i=NUM_LEDS-1; i>=0; i--) { // and here
                    setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                               ((sin(i+Position) * 127 + 128)/255)*green,
                               ((sin(i+Position) * 127 + 128)/255)*blue);
                  }
                  
                  showStrip();
                  delay(WaveDelay);
              }
            }
            

            Gizmo Props

          • May 6, 2020 - 4:20 AM - Hans - Author: Comment Link

            Thanks for chiming in Gizmo Props! Awesome! 

            Hans

      • Apr 27, 2018 - 2:48 PM - Sebastian Krupnik Comment Link

        Hi!  The “Compile” didn´t pass because the “SIN” function doesn´t exist on my project.

        Supposed this SIN function is included in the NEOPIXEL Library?

        Thanks for your support!!

        void loop() {
          RunningLights(0xff,0xff,0x00, 50);
        }
        void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
          int Position=0;
          
          for(int i=(NUM_LEDS*2)-1; i>=0; i--) // <-- opposite direction
          {
              Position++; // = 0; //Position + Rate;
              for(int i=0; i<NUM_LEDS; i++) {
                setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                           ((sin(i+Position) * 127 + 128)/255)*green,
                           ((sin(i+Position) * 127 + 128)/255)*blue);
              }
              
              showStrip();
              delay(WaveDelay);
          }
        }

        Reply

        Sebastian Krupnik

        • Apr 30, 2018 - 5:58 AM - hans - Author: Comment Link

          Hi Sebastian,

          the sin() function is a standard function that comes with the Arduino IDE (link).
          Since the code looks OK, my first guess would be to update your Arduino IDE to the latest version (link).

          Reply

          hans

          • Apr 30, 2018 - 6:28 PM - Sebastian Krupnik Comment Link

            Hi Hans, mi interface is for coding is https://build.particle.io/ (using a PHOTON). Not sure how to upgrade this interface. Have you know what to do?

            Thank you!!

            Sebastian Krupnik

          • May 9, 2018 - 2:56 AM - hans - Author: Comment Link

            Hi Sebastian,

            I have never worked with that tool, and unfortunately it seems required that one has to signs up. 
            Maybe other users/visitors are familiar with this tool and can assist?

            hans

  • Mar 19, 2017 - 4:29 PM - chris Comment Link

    hi im new to coding on Arduino but iv been trying to do the KITT effect (Cylon) for ages and just found this site yesterday iv managed to get it working but not liking the look of the KITT effect when i slow it down, iv set the speed to about “70” as i want it to look like the real KITT car but i can see the LED’s are not fading into the red as its going along.. it looks as if its just turning the led’s on from 0% brightness to 100% also the faded sides of the eye that I’m guessing jumps from 0% to 50% brightness.. so my question is can i make the effect better by fading the LED’s in as they go along.. for example each LED will not jump straight to 100 instead 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% brightness.. any help il be much appreciated.

    Reply

    chris

    • Mar 20, 2017 - 8:59 AM - hans - Author: Comment Link

      Hi Chris,

      that would most certainly be possible, maybe we should try to find a video that displays the 100% correct effect.
      I did play a little with fading (happened to be for a bouncing ball project), and selecting 10, 20,…,90, 100% is a little tricky since brightness does not behave in a linear way with LEDs.

      We can start a forum topic if you’d like.

      Reply

      hans

      • Mar 20, 2017 - 9:19 AM - Chris Comment Link

        Sure anything that would help me would be great also this is helping me learn to code 

        Reply

        Chris

  • Mar 26, 2017 - 4:42 PM - Moreno Antunes Comment Link

    Hello there Hans, and thank you very very much for this guide!

    I just started learning how to use the arduino, my idea was to have custom led configs on my pc case for fun, and I found out learning arduino with 2812b leds is a much better way to do this than lets say buying a retail product like NZXT Hue+.

    I have a question, I got it all working, but I need a way to either update the arduino data to change effects. 

    Is there a way to have many effects on the memory and by an USB command change between it? Or perhaps a way to double click a shortcut and it will directly upload a sketch to it?

    I used this program (https://github.com/CalcProgrammer1/KeyboardVisualizer) and got it to control the lighting via the COM port in real time, works great based on the music, is there a way to do it to change effects??

    Once again, thank you very much for the hard work!!

    Reply

    Moreno Antunes

    • Mar 27, 2017 - 10:46 AM - hans - Author: Comment Link

      Hi Moreno,

      glad to hear you’re having fun with these LEDs as well.
      In our Arduino forum, you’ll find a few topics covering the combining of all effects in one sketch.
      I’m planning on writing a dedicated article for that, but just simply haven’t gotten to it yet.

      So, it’s very well possible, just might take some work to get it going … 

      Reply

      hans

  • Apr 2, 2017 - 7:42 AM - candy Comment Link

    hello.. do you have a easy one of the code. when i copy the code mix with another one.. other function are not work … can you help me?

    Reply

    candy

  • Apr 2, 2017 - 6:50 PM - Jeffrey T Pruitt Comment Link

    This page is awesome. I’m trying to combine your fade code, with another “code” i found. 

    https://github.com/zatamite/Neopixel-heartbeat

    I basically want my Neopixel strip to beat like the program attached throughout the whole strip but with your fading script.

    Any thoughts???

    Reply

    Jeffrey T Pruitt

    • Apr 2, 2017 - 7:41 PM - hans - Author: Comment Link

      Hi Jeffrey,

      thanks for the compliment! 

      As for the heartbeat code you found, this can be modified to:

      void loop() {  
        // original uses 3 leds, in that case use:
        // heartbeat(3, random(255), random(255), random(255));
        
        // The next line uses all LEDs:
        heartbeat(NUM_LEDS, random(255), random(255), random(255));  
      }
      void heartbeat(int ledCount, byte red, byte green, byte blue) {
        byte brightnessStep = 3;
        
        for(int i = 0; i<ledCount; i++) {
          setPixel(i, red, green, blue);
        }
        showStrip();
        
        delay (20);
            
        for (int brightnessValue = 1 ; brightnessValue <252 ; brightnessValue = brightnessValue + brightnessStep){
          setBrightness(brightnessValue);
          showStrip();              
          delay(5);
        }
          
        for (int brightnessValue = 252 ; brightnessValue > 3 ; brightnessValue = brightnessValue - brightnessStep){
          setBrightness(brightnessValue);
          showStrip();              
          delay(3);
        }
        
        delay(10);
         
        brightnessStep = 6;
        
        for (int brightnessValue = 1 ; brightnessValue <255 ; brightnessValue = brightnessValue + brightnessStep){
          setBrightness(brightnessValue);
          showStrip();              
          delay(2);  
        }
        
        for (int brightnessValue = 255 ; brightnessValue > 1 ; brightnessValue = brightnessValue - brightnessStep){
          setBrightness(brightnessValue);
          showStrip();              
          delay(3);
        }
        
        delay (50); 
      } // I have never used the brightness function of either NeoPixel or FastLED, so I hope this works.
      void setBrightness(byte value) {
        #ifdef ADAFRUIT_NEOPIXEL_H
          // NeoPixel
         strip.setBrightness(value);
        #endif
        #ifndef ADAFRUIT_NEOPIXEL_H 
         // FastLED
         FastLED.setBrightness(value);
        #endif
      }

      This code should replace the following lines in the base code of this article:

      // *** REPLACE FROM HERE ***
      void loop() { 
       // ---> here we call the effect function <---
      }
      // ---> here we define the effect function <---
      // *** REPLACE TO HERE ***

      Please note that I did not have the opportunity to test this code, please let us know how well this does (or does not) work.
      Also note that I changed the variable names to make it more readable, and … keep in mind that I might have made typos … 

      Also keep in mind that the original code only uses 3 LEDs (see comments in the loop() section). 

      Reply

      hans

      • Apr 2, 2017 - 7:58 PM - Jeffrey T Pruitt Comment Link

        Thank you thank you thank you!!!!This did exactly what I was looking for, I’m just starting with Arduino, neopixel etc, so I’m still trying to figure out coding things so this is a HUGE help.
        Thanks again!

        Reply

        Jeffrey T Pruitt

      • Apr 2, 2017 - 8:17 PM - hans - Author: Comment Link

        You’re most welcome  …

        Did it work as expected?

        Reply

        hans

  • Apr 4, 2017 - 11:25 PM Comment Link
    PingBack: www.tianrandesign.com

    […] Arduino – LEDStrip effects for NeoPixel and FastLED […]

  • Apr 5, 2017 - 5:51 AM - lucky kang Comment Link

    hi there is anyone can tell me that these codes will work on RGB led strip as well thx

    Reply

    lucky kang

    • Apr 5, 2017 - 8:50 AM - hans - Author: Comment Link

      Hi Lucky,

      it depends on what RGB strips you’re using. The WS2811 and WS2812 are RGB LED strips running on 5V (typically). There are some cheap knock offs that use a different color order (GRB for example), but in essence that works just the same.

      Do you have any specifications?

      Reply

      hans

  • Apr 6, 2017 - 1:25 AM - lucky kang Comment Link
    • Apr 6, 2017 - 1:28 PM - hans - Author: Comment Link

      Hi Lucky,

      I can’t guarantee that. It states it’s RGB, but since sellers post whatever they like, there is no guarantee – one thing I noticed is that these LEDs are 12V, so I would not recommend using them.

      Reply

      hans

  • Apr 6, 2017 - 4:12 PM - lucky kang Comment Link

    can u recommend and good RGB led strips thx

    Reply

    lucky kang

    • Apr 6, 2017 - 4:27 PM - hans - Author: Comment Link

      I just ordered some strips from AliExpress – I had ordered from this seller before and they work very well.
      They are also very affordable. See this link.

      I always pick the 5 Meter strand with 60 LEDs per meter, with black PCB and IP65 (5M 60 IP65).

      The LEDs are waterproof and casted in some kind of solid transparent silicone, which makes it very well protected against dust, water, bugs etc etc. It also makes it look really nice with the black “PCB”. It’s $22.73 for a 5 meter strand – different sizes are available – at the time of this writing.

      Reply

      hans

      • Apr 6, 2017 - 9:00 PM - jony Comment Link

        hi i order ws2811 from ebay and the all three colour work except white why is that anyone help thx

        Reply

        jony

      • Apr 7, 2017 - 9:15 AM - hans - Author: Comment Link

        Hi Jony,

        if each color works, then white would be when all colors are ON.
        this should work for all types of LED strands. Now if the strand is not really a WS2811, it might become tricky to control the LED colors. Quite a lot of sellers advertise wrong or misleading information. Did you try some test code from the “Controlling LEDs with Arduino” article?

        Reply

        hans

  • Apr 6, 2017 - 8:29 PM - lucky kang Comment Link

    ok

    Reply

    lucky kang

  • Apr 7, 2017 - 5:11 PM - jony Comment Link

    so can you tell me how can i do that please thx

    Reply

    jony

    • Apr 8, 2017 - 12:16 PM - hans - Author: Comment Link

      Hi Jony,

      did you run the test sketches?
      Normally, to get white, one would set the color to 0xff, 0xff, 0xff (all 3 colors to max).

      Reply

      hans

  • Apr 9, 2017 - 6:32 AM - prof Comment Link

    Hi tweaking4all.com. My English translator level is Google, I apologize for the mistakes.

    – I googled a lot about LED on WS2812b, and came across your magic site, which helped me a lot in mastering. But I have a few questions, tell or send me to the desired section of your forum.
    I
    downloaded “AllLEDEffects-FastLED” unlocked ALL effects, but in the
    case of “Bouncing Balls Multi Color” and just Bouncing Balls it stays on
    this effect and that’s it.
    In the case of “Fire” if something is unlocked in addition to this effect, then “Fire” simply does not play.

    Questions:
    1. How to remove these shortcomings?
    2. How to make a random effect switching time, or every 10 minutes?
    3. In the “Bouncing Balls Multi Color” effect, do random colors?

    Reply

    prof

    • Apr 10, 2017 - 10:18 AM - hans - Author: Comment Link

      Hi Prof,

      well, I’d start with making those 2 effects work properly. 
      You can create the code from scratch by copying the initial framework, for the library you want to use, and then paste in the effect code.

      As for multiple effects in one sketch, consult our Arduino Forum, there are a few topics on this, for example this one, that should help get you started.

      Reply

      hans

  • Apr 17, 2017 - 5:04 AM - lucky kang Comment Link

    hi guys is anyone can help me i jst wanna add two pir sensor with these codes top and bottom im bit confuse with wiring and coding is anyone knows how to do it thx  

    Reply

    lucky kang

  • Apr 19, 2017 - 3:43 PM - John Comment Link

    The project i m working on is stair project one PIR sensor bottom stair and one top so when bottom sensor activate the light start from bottom to top when top sensor activate the light start top to bottom and also how to do the wiring also thx

    Similar to this video

    https://www.youtube.com/watch?v=lNxgYWHewzg

    Reply

    John

  • Jun 25, 2017 - 11:58 PM - Wrybread Comment Link

    None of the videos are working. I’d love to see the examples though, is it easy enough to fix them?

    Or are they working for other people?

    Reply

    Wrybread

    • Jun 26, 2017 - 8:35 AM - hans - Author: Comment Link

      Hi Wrybread,

      Could you let me know which Operating System and which browser versions you’re using?
      I have seen the videos causing issues with old Android devices, but with Windows and Mac I have not seen any issues yet.

      If you have an older OS, consider trying Google Chrome.

      Reply

      hans

  • Jul 1, 2017 - 3:39 PM - Daniel Comment Link

    Hello friends! I
    have very little knowledge on the subject but, I would like to join
    several of these codes mentioned in several strips of Led, say, 8;
    Therefore, how can the code be assembled in this way?

    Thank you all

    Reply

    Daniel

    • Jul 2, 2017 - 12:20 PM - hans - Author: Comment Link

      Hi Daniel!

      Welcome!

      I’m not sure what you mean? Are you thinking of running 8 strips in parallel?

      Reply

      hans

  • Jul 25, 2017 - 2:11 PM - Dan Comment Link

    Hi,

    I’m a complete novice with Arduino and Neopixels, and by novice I mean I’ve never coded anything before! I’ve picked up some bits and pieces but I’ve found that most tutorials jump through stages without actually explaining the basics, pretty much just copy and paste code which isn’t great for learning! I’ve been attempting the Rainbow Cycle sketch but I get an error message saying the the number of LEDs has not been declared, where do I put this value in the code?

    I’m also hoping to loop 5 rainbow cycles and then run a colour wipe through every colour on my RGBW Neopixels before returning to the rainbow cycle, is this possible to run on the Arduino as one sketch?

    Thanks in advance!

    Reply

    Dan

    • Jul 25, 2017 - 3:32 PM - hans - Author: Comment Link

      Hi Dan,

      you’re probably right about the lack of detailed info, since most assume some basic knowledge.
      Maybe this little intro course is useful, in case you want to dig a little deeper.

      As for the number of defined LEDs, the line

      #define NUM_LEDS 60 

      defines the number of LEDs in your strand. You’ll see it in both examples (NeoPixel and FastLED).

      Doing 5x rainbow, and then a colour wipe for several colors is most certainly possible.

      You’d need something like this

      void loop() {
        for(i=0;i<5;i++) { rainbowCycle(20); }
        colorWipe(0xff,0x00,0x00, 50);
        colorWipe(0x00,0xff,0x00, 50);
        colorWipe(0x00,0x00,0xff, 50);
      }
      void rainbowCycle(int SpeedDelay) {
        byte *c;
        uint16_t i, j;
        for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
          for(i=0; i< NUM_LEDS; i++) {
            c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
            setPixel(i, *c, *(c+1), *(c+2));
          }
          showStrip();
          delay(SpeedDelay);
        }
      }
      byte * Wheel(byte WheelPos) {
        static byte c[3];
        
        if(WheelPos < 85) {
         c[0]=WheelPos * 3;
         c[1]=255 - WheelPos * 3;
         c[2]=0;
        } else if(WheelPos < 170) {
         WheelPos -= 85;
         c[0]=255 - WheelPos * 3;
         c[1]=0;
         c[2]=WheelPos * 3;
        } else {
         WheelPos -= 170;
         c[0]=0;
         c[1]=WheelPos * 3;
         c[2]=255 - WheelPos * 3;
        }
        return c;
      }
      void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
        for(uint16_t i=0; i<NUM_LEDS; i++) {
            setPixel(i, red, green, blue);
            showStrip();
            delay(SpeedDelay);
        }
      }

      As you might see; I combined the code of both effects, and call them in the loop().
      It does the 5xrainbow, wipe for Red, wipe for Green, wipe for Blue.
      After it completed that, it will do the loop again, so effectively do 5xRainbow, and 3x wipe.

      Keep in mind that the code needs to be pasted in the framework, replacing the text between the lines (maybe you forgot that earlier):

      // *** REPLACE FROM HERE ***

      and

      // *** REPLACE TO HERE ***

      If you want to add more colors, you can add a line like this for each color you’d want:

      colorWipe(0x00,0xff,0x00, 50); // red, green, blue, here: Green

      If you want a ton of colors for the colour wipe, then consider using for-loops (see also the little course).
      For example:

      for(red=0;red<255;red++) 
      {
        for(green=0;green<255;green++)
        {
          for(blue=0;blue<255;blue++)
          {
            colorWipe(red,green,blue,50);
          }
        }
      }

      This example would go through all colors (16 million), so you might want to narrow that down haha. 

      Hope this is helpful.

      Reply

      hans

      • Jul 26, 2017 - 4:04 AM - Dan Comment Link

        Thanks Hans, this is great! I’ll get stuck into all of that, plenty of material to get me started!

        Thanks again

        Reply

        Dan

        • Jul 26, 2017 - 11:09 AM - hans - Author: Comment Link

          Cool! Well, feel free to ask if you run into issue or have questions … 

          Reply

          hans

          • Jul 30, 2017 - 10:43 AM - Dan Comment Link

            I’ve been messing about with all of this and I seem to be getting a warning message saying that I have created a compound expression list after dealing with a declaration problem, will this cause any problems with the neopixels? See below;

            Users/Daniel/Documents/Arduino/RainbowCycle/RainbowCycle.ino: In function ‘void rainbowCycle(int)’:

            /Users/Daniel/Documents/Arduino/RainbowCycle/RainbowCycle.ino:35:40: warning: expression list treated as compound expression in initializer [-fpermissive]

             int setPixel(i, *c, *(c+1), *(c+2));

                                                    ^

            /Users/Daniel/Documents/Arduino/RainbowCycle/RainbowCycle.ino: In function ‘void colorWipe(byte, byte, byte, int)’:

            /Users/Daniel/Documents/Arduino/RainbowCycle/RainbowCycle.ino:65:38: warning: expression list treated as compound expression in initializer [-fpermissive]

             int setPixel(i, red, green, blue);

                                                  ^

            Dan

          • Jul 30, 2017 - 6:40 PM - hans - Author: Comment Link

            Hi Dan,

            it is a warning which most likely will not stop your program from running. It does point to something not being 100% perfect though.

            I haven’t ran into this problem before so, just a guess here; look for this line in your code (defining the function SetPixel):

            void setPixel(int Pixel, byte red, byte green, byte blue) {

            and replace that line with:

            void setPixel(int Pixel, int red, int green, int blue) {

            But there could be other reasons – Maybe you can post your code in our Arduino Forum so I can look at it (without making this treat super long) … 

            hans

  • Aug 2, 2017 - 7:46 AM Comment Link
    PingBack: bitknitting.wordpress.com

    […] Tweaking4All’s also really nice Fire neopixel sketch.  Same comments as with John’s work.  THANK YOU. […]

  • Aug 7, 2017 - 9:09 AM - Tony Comment Link

    First off, thank you so much for this resource!! So great!

    Question:  Using the “Fire” code to create a flame inside an outdoor lamp post w/diffuser to simulate a flame.   I’d like to change the flame colors to have more orange and less red.  Also would like less white and more yellow?  Could you recommend changes to the Fire code to modify the output as such?

    Thanks in advance.

    Reply

    Tony

    • Aug 12, 2017 - 4:29 PM - hans - Author: Comment Link

      Hi Tony,

      I have not tested this, but in the last procedure used by the fire code (setPixelHeatColor()), you could play a little with the “Red” value when the pixel colors are calculated, worse thing that can happen is that the colors will be off 

      void setPixelHeatColor (int Pixel, byte temperature) {
        // Scale 'heat' down from 0-255 to 0-191
        byte t192 = round((temperature/255.0)*191);
       
        // calculate ramp up from
        byte heatramp = t192 & 0x3F; // 0..63
        heatramp <<= 2; // scale up to 0..252
       
        // figure out which third of the spectrum we're in:
        if( t192 > 0x80) { // hottest
          // original: setPixel(Pixel, 255, 255, heatramp);
          setPixel(Pixel, 200, 255, heatramp); // changed res 255 to red 200
        } else if( t192 > 0x40 ) { // middle
          // original: setPixel(Pixel, 255, heatramp, 0);
          setPixel(Pixel, 200, heatramp, 0); // changed red 255 to red 200
        } else { // coolest
          setPixel(Pixel, heatramp, 0, 0);
        }
      }
      Reply

      hans

      • Aug 13, 2017 - 7:40 AM - Tony Comment Link

        Thank you for the reply.  I actually modified the code on my own in a similar manner.

        Reply

        Tony

  • Sep 13, 2017 - 3:36 PM Comment Link
  • Sep 24, 2017 - 2:45 PM - Dhiraj Kumar Comment Link

    Dear All,

    I am new to this project.I don’t have any idea about coding but i want to run all this code on a neopixel stripe. How to combine all these codes to run in one single sketch.

    Reply

    Dhiraj Kumar

  • Sep 27, 2017 - 7:40 PM - Daniel Fernandes Comment Link

    I would like to repeat the Dhiraj Kumar’s question!

    Reply

    Daniel Fernandes

    • Sep 30, 2017 - 1:32 PM - hans - Author: Comment Link

      Hi Daniel (and Dhiraj),

      there have been a few requests for this and some of the users have worked on it in the forum – however, it will take some work and reading to get this done, which might not be the easiest for a beginner.

      If users could tell me how they would like to see then, then I’ll try to create code to include all effects.
      Do we prefer toggling effects with a push button? Or based on a predefined pattern?

      Reply

      hans

  • Sep 27, 2017 - 10:17 PM - John Comment Link

    It is really refreshing to find someone such as yourself who has the knowledge, and is willing to share it – without a demeaning / snarky attitude.

    Thank you!

    John

    Reply

    John

    • Sep 30, 2017 - 1:38 PM - hans - Author: Comment Link

      Hi John,

      thank you for the very nice compliment. It’s very much appreciated and definitely a motivator to keep working on more articles.  
      And the relaxed attitude is what I’m going for. I like to show folks how things can be done, in a fun way. The more folks that participate with the same mindset, the more fun it will be for all of us … 

      Reply

      hans

  • Sep 30, 2017 - 7:58 AM - Brian Comment Link

    Thanks, great stuff.

    For the Particle.io I needed to add one line after including the FastLED library:

    #include <FastLED.h>

    FASTLED_USING_NAMESPACE

    Unlike Arduino, the Particle.io uses namespace and so requires this single line to compile correctly. More about it here. 

    Reply

    Brian

  • Oct 3, 2017 - 9:07 PM Comment Link
    PingBack: cvallee.com

    […] ici est LEDStrip Effect – Snow Sparkle, mais a cette adresse on peux trouver plein d’autres […]

  • Oct 13, 2017 - 5:20 PM - Ian Comment Link

    Thank you for sharing your fantastic work. I arrived here after searching or neopixel fire. I wanted to bring a big picture of a rocket to life on my sons wall. I plan on using a shorter strip, so I think with a few little tweaks your code will be work great for me.

    I love the other effects too, so I’m going to have to think of where I can use them.

    Reply

    Ian

    • Oct 15, 2017 - 4:25 AM - hans - Author: Comment Link

      Hi Ian,

      Thank you for taking the time to post a thank-you – it’s very much appreciated. Glad to hear you’re having fun!
      I guess I should have placed a warning, the darn LED strips can be very addicting! 

      Reply

      hans

  • Oct 15, 2017 - 7:23 AM - Henrik Lauridsen Comment Link

    Thank you very much for this great site and nice examples

    Reply

    Henrik Lauridsen

    • Oct 18, 2017 - 4:39 AM - hans - Author: Comment Link

      Hi Hendrik!

      Thank you so much for taking the time to post a thank-you note. It’s very much appreciated.
      Glad to hear that you enjoy the website! 

      Reply

      hans

  • Oct 21, 2017 - 4:49 PM - Dai Comment Link

    Hi, and thank you for your examples they really have made it easier for me to get some good effects as I start getting my christmas led displays ready (it’s my first year doing my own). And in response to Daniel and Dhiraj’s question, I have created a single sketch that includes all your examples as their own functions and then call them in the order I prefer in the loop section, I now have my pro-mini running my first example string with hours of different effects before they get repeated. These have saved me a huge amount of time and I can’t praise you enough. Thank You. :)

    Reply

    Dai

    • Oct 22, 2017 - 7:22 AM - hans - Author: Comment Link

      Hi Dai!

      That’s awesome and thanks for sharing!
      Feel free to post the sketch if you’re comfortable doing that – once I get the time to play with that, I’ll try to write an article on how to do that and your input would be very welcome. 

       

      Reply

      hans

  • Oct 22, 2017 - 9:22 AM - Dai Comment Link

    Here is my sketch that I have been using to get the timings sorted out (Sorry if it is too long), I have had to make a few adjustments to your demos to prevent infinite loop in BouncingBalls and BouncingColoredBalls , which is now simply a for loop which runs the amount of times specified in the extra parameter “timesToRun”. Also there are some short routines that would need a for loop in the main loop to make them run a certain amount of times (like I have done for the Fire function). I also added a colorWipeReverse function which as the name suggests simply goes the other way.

    You will notice I have a couple of Serial.print(millis());, one at the beginning of the main loop and one at the end, this is to tell me the timing of each loop as I change settings. I am doing that so that I can set each effect to last X amount of time.

    There are a couple of other changes you may find from your examples although I did not make note of what I was changing but I’m sure you will spot them.

    I hope this is of some use to others as it is just the beginning of setting my own strings, so not perfect, but usable.

    And just a note about hardware, I am using Arduino Uno for testing (as it is easer) and then a pro-mini in the actual project. The led string I am using with these have 3 leds from each ws2811 IC so the 14 pixels listed are actually 42 on the test string, this may make the timings I have used a little more understandable.

    #include "FastLED.h"
    #define NUM_LEDS 14
    #define DATA_PIN 6
    CRGB leds[NUM_LEDS];

    void setup() {
    Serial.begin(9600);
    LEDS.addLeds<WS2811,DATA_PIN,BRG>(leds,NUM_LEDS);
    LEDS.setBrightness(255);
    }

    void loop(){
    Serial.println(millis());
    //next two together
    // byte colors[3][3]={{0xff,0,0},{0xff,0xff,0xff},{0,0,0xff}};
    // BouncingColoredBalls(3,colors,1000);
    // BouncingBalls(0xff,0,0,3,1000);
    // for(int count=0;count<500;count++){
    // Fire(55,120,15);
    // }
    // theaterChaseRainbow(100);
    // theaterChase(0xff,0,0,100);
    // rainbowCycle(20);
    //next two together
    colorWipe(255,0,0,100);
    colorWipe(0,0,0,100);
    //next two together
    colorWipeReverse(0,128,0,100);
    colorWipeReverse(0,0,0,100);
    // RunningLights(0,0,128,300);
    // SnowSparkle(0,0,0,20,random(100,1000));
    // Sparkle(random(255),random(255),random(60),200);
    // TwinkleRandom(20,100,false);
    // Twinkle(0xff,0,0,20,100,false);
    // NewKITT(0xff,0,0,1,100,100);
    // CylonBounce(0xff,0,0,2,100,0);
    // HalloweenEyes(0xff,0x00,0x00,1,2,true,random(5,50),random(50,150),random(1000,10000));
    // Strobe(255,0,0,10,50,1000);
    // FadeInOut(0xff,0x00,0x00); // red
    // FadeInOut(0xff,0xff,0xff); // white
    // FadeInOut(0x00,0x00,0xff); // blue
    // RGBLoop();
    Serial.println(millis());
    }

    void BouncingColoredBalls(int BallCount, byte colors[][3], int timesToRun) {
    float Gravity = -9.81;
    int StartHeight = 1;
    float Height[BallCount];
    float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
    float ImpactVelocity[BallCount];
    float TimeSinceLastBounce[BallCount];
    int Position[BallCount];
    long ClockTimeSinceLastBounce[BallCount];
    float Dampening[BallCount];
    for (int i = 0 ; i < BallCount ; i++) {
    ClockTimeSinceLastBounce[i] = millis();
    Height[i] = StartHeight;
    Position[i] = 0;
    ImpactVelocity[i] = ImpactVelocityStart;
    TimeSinceLastBounce[i] = 0;
    Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
    }
    for (int a = 0;a<timesToRun;a++) {
    for (int i = 0 ; i < BallCount ; i++) {
    TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
    Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
    if ( Height[i] < 0 ) {
    Height[i] = 0;
    ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
    ClockTimeSinceLastBounce[i] = millis();
    if ( ImpactVelocity[i] < 0.01 ) {
    ImpactVelocity[i] = ImpactVelocityStart;
    }
    }
    Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
    }
    for (int i = 0 ; i < BallCount ; i++) {
    setPixel(Position[i],colors[i][0],colors[i][1],colors[i][2]);
    }
    showStrip();
    setAll(0,0,0);
    }
    }

    void BouncingBalls(byte red, byte green, byte blue, int BallCount, int timesToRun) {
    float Gravity = -9.81;
    int StartHeight = 1;
    float Height[BallCount];
    float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
    float ImpactVelocity[BallCount];
    float TimeSinceLastBounce[BallCount];
    int Position[BallCount];
    long ClockTimeSinceLastBounce[BallCount];
    float Dampening[BallCount];
    for (int i = 0 ; i < BallCount ; i++) {
    ClockTimeSinceLastBounce[i] = millis();
    Height[i] = StartHeight;
    Position[i] = 0;
    ImpactVelocity[i] = ImpactVelocityStart;
    TimeSinceLastBounce[i] = 0;
    Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
    }
    for (int a = 0;a<timesToRun;a++) {
    for (int i = 0 ; i < BallCount ; i++) {
    TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
    Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
    if ( Height[i] < 0 ) {
    Height[i] = 0;
    ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
    ClockTimeSinceLastBounce[i] = millis();
    if ( ImpactVelocity[i] < 0.01 ) {
    ImpactVelocity[i] = ImpactVelocityStart;
    }
    }
    Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
    }
    for (int i = 0 ; i < BallCount ; i++) {
    setPixel(Position[i],red,green,blue);
    }
    showStrip();
    setAll(0,0,0);
    }
    }

    void Fire(int Cooling, int Sparking, int SpeedDelay) {
    static byte heat[NUM_LEDS];
    int cooldown;
    // Step 1. Cool down every cell a little
    for( int i = 0; i < NUM_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);
    if(cooldown>heat[i]) {
    heat[i]=0;
    } else {
    heat[i]=heat[i]-cooldown;
    }
    }
    // Step 2. Heat from each cell drifts 'up' and diffuses a little
    for( int k= NUM_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
    }
    // Step 3. Randomly ignite new 'sparks' near the bottom
    if( random(255) < Sparking ) {
    int y = random(7);
    heat[y] = heat[y] + random(160,255);
    //heat[y] = random(160,255);
    }
    // Step 4. Convert heat to LED colors
    for( int j = 0; j < NUM_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
    }
    showStrip();
    delay(SpeedDelay);
    }

    void setPixelHeatColor (int Pixel, byte temperature) {
    // Scale 'heat' down from 0-255 to 0-191
    byte t192 = round((temperature/255.0)*191);
    // calculate ramp up from
    byte heatramp = t192 & 0x3F; // 0..63
    heatramp <<= 2; // scale up to 0..252
    // figure out which third of the spectrum we're in:
    if( t192 > 0x80) { // hottest
    setPixel(Pixel, 255, 255, heatramp);
    } else if( t192 > 0x40 ) { // middle
    setPixel(Pixel, 255, heatramp, 0);
    } else { // coolest
    setPixel(Pixel, heatramp, 0, 0);
    }
    }

    void theaterChaseRainbow(int SpeedDelay) {
    byte *c;
    for (int j=57; j < 256; j++) { // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
    for (int i=0; i < NUM_LEDS; i=i+3) {
    c = Wheel( (i+j) % 255);
    setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on
    }
    showStrip();
    delay(SpeedDelay);
    for (int i=0; i < NUM_LEDS; i=i+3) {
    setPixel(i+q, 0,0,0); //turn every third pixel off
    }
    }
    }
    }

    void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
    for (int j=0; j<10; j++) { //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
    for (int i=0; i < NUM_LEDS; i=i+3) {
    setPixel(i+q, red, green, blue); //turn every third pixel on
    }
    showStrip();
    delay(SpeedDelay);
    for (int i=0; i < NUM_LEDS; i=i+3) {
    setPixel(i+q, 0,0,0); //turn every third pixel off
    }
    }
    }
    }

    void rainbowCycle(int SpeedDelay) {
    byte *c;
    uint16_t i, j;
    for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< NUM_LEDS; i++) {
    c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
    setPixel(i, *c, *(c+1), *(c+2));
    }
    showStrip();
    delay(SpeedDelay);
    }
    }

    byte * Wheel(byte WheelPos) {
    static byte c[3];
    if(WheelPos < 85) {
    c[0]=WheelPos * 3;
    c[1]=255 - WheelPos * 3;
    c[2]=0;
    } else if(WheelPos < 170) {
    WheelPos -= 85;
    c[0]=255 - WheelPos * 3;
    c[1]=0;
    c[2]=WheelPos * 3;
    } else {
    WheelPos -= 170;
    c[0]=0;
    c[1]=WheelPos * 3;
    c[2]=255 - WheelPos * 3;
    }
    return c;
    }

    void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
    for(uint16_t i=0; i<NUM_LEDS; i++) {
    setPixel(i, red, green, blue);
    showStrip();
    delay(SpeedDelay);
    }
    }

    void colorWipeReverse(byte red, byte green, byte blue, int SpeedDelay){
    int a = 0;
    for(uint16_t i=NUM_LEDS; i>0; i--) {
    a = i-1;
    setPixel(a, red, green, blue);
    showStrip();
    delay(SpeedDelay);
    }
    }

    void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
    int Position=0;
    for(int i=0; i<NUM_LEDS*2; i++)
    {
    Position++; // = 0; //Position + Rate;
    for(int i=0; i<NUM_LEDS; i++) {
    setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
    ((sin(i+Position) * 127 + 128)/255)*green,
    ((sin(i+Position) * 127 + 128)/255)*blue);
    }
    showStrip();
    delay(WaveDelay);
    }
    }

    void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
    setAll(red,green,blue);
    int Pixel = random(NUM_LEDS);
    setPixel(Pixel,0xff,0xff,0xff);
    showStrip();
    delay(SparkleDelay);
    setPixel(Pixel,red,green,blue);
    showStrip();
    delay(SpeedDelay);
    }

    void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
    int Pixel = random(NUM_LEDS);
    setPixel(Pixel,red,green,blue);
    showStrip();
    delay(SpeedDelay);
    setPixel(Pixel,0,0,0);
    }

    void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
    setAll(0,0,0);
    for (int i=0; i<Count; i++) {
    setPixel(random(NUM_LEDS),random(0,255),random(0,255),random(0,255));
    showStrip();
    delay(SpeedDelay);
    if(OnlyOne) {
    setAll(0,0,0);
    }
    }
    delay(SpeedDelay);
    }

    void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
    setAll(0,0,0);
    for (int i=0; i<Count; i++) {
    setPixel(random(NUM_LEDS),red,green,blue);
    showStrip();
    delay(SpeedDelay);
    if(OnlyOne) {
    setAll(0,0,0);
    }
    }
    delay(SpeedDelay);
    }

    void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
    RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
    LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
    OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
    CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
    LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
    RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
    OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
    CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
    }

    void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
    for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
    setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
    setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
    }
    delay(ReturnDelay);
    }

    void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
    for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
    setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
    setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
    }
    delay(ReturnDelay);
    }

    void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
    for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
    setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
    }
    delay(ReturnDelay);
    }

    void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
    for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
    setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
    }
    delay(ReturnDelay);
    }

    void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
    for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
    setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
    }
    delay(ReturnDelay);
    for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
    setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
    }
    delay(ReturnDelay);
    }

    void HalloweenEyes(byte red, byte green, byte blue,
    int EyeWidth, int EyeSpace,
    boolean Fade, int Steps, int FadeDelay,
    int EndPause){
    randomSeed(analogRead(0));
    int i;
    int StartPoint = random( 0, NUM_LEDS - (2*EyeWidth) - EyeSpace );
    int Start2ndEye = StartPoint + EyeWidth + EyeSpace;
    for(i = 0; i < EyeWidth; i++) {
    setPixel(StartPoint + i, red, green, blue);
    setPixel(Start2ndEye + i, red, green, blue);
    }
    showStrip();
    if(Fade==true) {
    float r, g, b;
    for(int j = Steps; j >= 0; j--) {
    r = j*(red/Steps);
    g = j*(green/Steps);
    b = j*(blue/Steps);
    for(i = 0; i < EyeWidth; i++) {
    setPixel(StartPoint + i, r, g, b);
    setPixel(Start2ndEye + i, r, g, b);
    }
    showStrip();
    delay(FadeDelay);
    }
    }
    setAll(0,0,0); // Set all black
    delay(EndPause);
    }

    void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
    for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip();
    delay(FlashDelay);
    }
    delay(EndPause);
    }

    void FadeInOut(byte red, byte green, byte blue){
    float r, g, b;
    for(int k = 0; k < 256; k=k+1) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
    }
    for(int k = 255; k >= 0; k=k-2) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
    }
    }

    void RGBLoop(){
    for(int j = 0; j < 3; j++ ) {
    for(int k = 0; k < 256; k++) {
    switch(j) {
    case 0: setAll(k,0,0); break;
    case 1: setAll(0,k,0); break;
    case 2: setAll(0,0,k); break;
    }
    showStrip();
    delay(3);
    }
    for(int k = 255; k >= 0; k--) {
    switch(j) {
    case 0: setAll(k,0,0); break;
    case 1: setAll(0,k,0); break;
    case 2: setAll(0,0,k); break;
    }
    showStrip();
    delay(3);
    }
    }
    }
    void showStrip() {
    FastLED.show();
    }

    void setPixel(int Pixel, byte red, byte green, byte blue) {
    leds[Pixel].r = red;
    leds[Pixel].g = green;
    leds[Pixel].b = blue;
    }

    void setAll(byte red, byte green, byte blue) {
    for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
    }
    showStrip();
    }
    Reply

    Dai

    • Oct 23, 2017 - 5:03 AM - hans - Author: Comment Link

      Hi Dai,

      thank you so much for taking the time to post the code – I’m sure others will love it (as do I).

      Well done! 

      Reply

      hans

    • Oct 23, 2017 - 1:19 PM - Spike Comment Link

      Hi Dai,

      I would like to add my appreciation too. You have done an awesome job and I plan to give it a try, as soon as I can get the time.

      Thank you for sharing your code.

      Reply

      Spike

      • Oct 23, 2017 - 2:38 PM - Dai Comment Link

        Thank you Spike, I’m glad you like it, but the thanks should go to Hans as it is 99% his code, I just copy/pasted it all into one sketch ( with a couple of very minor tweaks. )

        Reply

        Dai

      • Oct 24, 2017 - 2:10 AM - hans - Author: Comment Link

        It’s all about team work! And LED strips are fun to play with hahah 

        Reply

        hans

  • Oct 22, 2017 - 2:33 PM - astro0302 Comment Link

    Thanks for your examples! These were a great inspiration to me. 

    So now, I want to show a rainbow, but not cycling from right to left or left to right. All 150 LEDs should show the same color value and change the rainbow colors.  

    How can I do this?

    Reply

    astro0302

    • Oct 23, 2017 - 5:34 AM - hans - Author: Comment Link

      Hi Astro0302!

      The modification for that shouldn’t be too hard.
      Try something like this:

      void rainbowCycle(int SpeedDelay) {
        byte *c;
        uint16_t i, j;
        for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
          c=Wheel(((i * 256 / NUM_LEDS) + j) & 255); // color selection used to be in the "i" loop
          for(i=0; i< NUM_LEDS; i++) {
            setPixel(i, *c, *(c+1), *(c+2));
          }
          showStrip();
          delay(SpeedDelay);
        }
      }

      You see the two for loops? The first one cycles colors (j), and the second one addresses each LED (i).
      Instead of doing a color change for each LED, I moved the color selection out of that loop (i).
      So it selects a color and then applies it to all LEDs.
      Now, I did not test this (I’m traveling) so it might need a little tweaking, but it will get you started.
      If you have a working sketch, then please feel free to post it here.

      Reply

      hans

    • Oct 23, 2017 - 5:36 AM - Dai Comment Link

      I have this sketch that is part of a sequence I am testing at the moment, not a finished one but might be useful to you. Obviously you will need to change the settings for your own pixel type and quantity but it works on my test strip. You can change the colour sequence in the sketch in each “colorStep” using RGB values.

      #include "FastLED.h"
      #define NUM_LEDS 14
      #define DATA_PIN 6
      CRGB leds[NUM_LEDS];

      void setup() {
      LEDS.addLeds<WS2811,DATA_PIN,BRG>(leds,NUM_LEDS);
      LEDS.setBrightness(255);
      }

      void loop() {
      fader();
      }

      void fader(){
      for( int colorStep=0; colorStep <= 255; colorStep++ ) {
      int r = 255;
      int g = 0;
      int b = colorStep;
      for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
      }
      delay(10);
      FastLED.show();
      }
      for( int colorStep=255; colorStep >= 0; colorStep-- ) {
      int r = colorStep;
      int g = 0;
      int b = 255;
      for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
      }
      delay(10);
      FastLED.show();
      }
      for( int colorStep=0; colorStep <= 255; colorStep++ ) {
      int r = 0;
      int g = colorStep;
      int b = 255;
      for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
      }
      delay(10);
      FastLED.show();
      }
      for( int colorStep=255; colorStep >= 0; colorStep-- ) {
      int r = 0;
      int g = 255;
      int b = colorStep;
      for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
      }
      delay(10);
      FastLED.show();
      }
      for( int colorStep=0; colorStep <= 255; colorStep++ ) {
      int r = colorStep;
      int g = 255;
      int b = 0;
      for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
      }
      delay(10);
      FastLED.show();
      }
      for( int colorStep=255; colorStep >= 0; colorStep-- ) {
      int r = 255;
      int g = colorStep;
      int b = 0;
      for(int x = 0; x < NUM_LEDS; x++){
      leds[x] = CRGB(r,g,b);
      }
      delay(10);
      FastLED.show();
      }
      }
      Reply

      Dai

      • Oct 23, 2017 - 5:44 AM - Dai Comment Link

        Sorry, posted around the same time as Hans, and his solution is far more elegant than mine.

        Reply

        Dai

  • Oct 22, 2017 - 8:43 PM - John Comment Link

    Nice work, Dai.

    I see you have used the ws2811 in your sketch, and I’m fairly new at this, so please bear with me.

    I’ve been running various test sketches using WS2812 and a 144 pixel strip. Fascinating what can be done with one data wire!

    If you have a couple of minutes, could you comment on my question, below?

    If I were to change “#define NUM_LEDS 14” to “#define NUM_LEDS 144”, and “LEDS.addLeds<WS2811,DATA_PIN,BRG>(leds,NUM_LEDS);” to the specification line for the WS2812, could I expect the sketch to work?

    Thanks.

    John

    Reply

    John

    • Oct 23, 2017 - 5:20 AM - hans - Author: Comment Link

      Hi John,

      It will work just fine with the 2812 as well.
      You are right though that some of the settings need to be modified to match the 2812 and the LED count you’d like to use. 
      The “addLeds” line might not need to be changed, since i seem to have used that as well even though I have a 2812 strip hahah … 

      Reply

      hans

      • Oct 23, 2017 - 5:40 AM - Dai Comment Link

        Yes, and one thing you might need to change would be the “BRG” in the “addLeds” line, some are GRB and some RGB, I had to adjust it to suit my pixels.

        Reply

        Dai

      • Oct 26, 2017 - 8:18 PM - circuitdriver Comment Link

        Got the sketch working just fine. Now comes the fun of tweaking it!

        A question on the lines below:

        RunningLights(0,0,128,300);

        Strobe(255,0,0,10,50,1000);

        FadeInOut(0xff,0x00,0x00); // red

        FadeInOut(0xff,0xff,0xff); // white

        FadeInOut(0x00,0x00,0xff); // blue

        Why do some lines use Hex color designation, and some use the RGB color names? Are they interchangeable, or are there coding reasons why one or the other is used?
        Thanks.John

        Reply

        circuitdriver

        • Oct 28, 2017 - 4:16 AM - hans - Author: Comment Link

          Hi John,

          Very good question … I guess that is my sloppiness ie. not always working consistently, especially when a project takes several days and effects have been written on different days. 

          Anyhoo … Decimal numbers and hex numbers are indeed interchangeable. 

          Reply

          hans

          • Oct 28, 2017 - 6:46 AM - Dai Comment Link

            Just to add that if you copied my sketch there would be some that I have changed as I have got used to using decimals for the brightness level and have changed some of them to make it easier for me to understand.

            Dai

          • Oct 30, 2017 - 5:52 AM - hans - Author: Comment Link

            That’s a good plan!

            I like hex numbers because they look more consistent (always 0x plus 2 characters), but I agree that decimal numbers are easier to read for us humans 

            hans

  • Nov 5, 2017 - 3:06 AM - fred49 Comment Link

    Multi Color Bouncing Balls
    Hi !Could show me in the code of “Multi Color Bouncing Balls” how to invert the show. For easy wiring of my strip led , I want that the first led is the number 15 ” Starting led is 15 instead of 0″
    Please explain me !
    thank a lot !fred

    Reply

    fred49

    • Nov 5, 2017 - 2:27 PM - hans - Author: Comment Link

      Hi

      Inverting the order should not be too hard.
      Try the following code (I have not had a chance to test this, but I’m confident that it will work OK):

      void loop() {
        BouncingBalls(0xff,0,0, 3);
      }
      void BouncingBalls(byte red, byte green, byte blue, int BallCount) {
        float Gravity = -9.81;
        int StartHeight = 1;
        
        float Height[BallCount];
        float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
        float ImpactVelocity[BallCount];
        float TimeSinceLastBounce[BallCount];
        int Position[BallCount];
        long ClockTimeSinceLastBounce[BallCount];
        float Dampening[BallCount];
        
        for (int i = 0 ; i < BallCount ; i++) {   
          ClockTimeSinceLastBounce[i] = millis();
          Height[i] = StartHeight;
          Position[i] = 0; 
          ImpactVelocity[i] = ImpactVelocityStart;
          TimeSinceLastBounce[i] = 0;
          Dampening[i] = 0.90 - float(i)/pow(BallCount,2); 
        }
        while (true) {
          for (int i = 0 ; i < BallCount ; i++) {
            TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
            Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
        
            if ( Height[i] < 0 ) {                      
              Height[i] = 0;
              ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
              ClockTimeSinceLastBounce[i] = millis();
        
              if ( ImpactVelocity[i] < 0.01 ) {
                ImpactVelocity[i] = ImpactVelocityStart;
              }
            }
            Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
          }
        
          for (int i = 0 ; i < BallCount ; i++) {
            setPixel((NUM_LEDS - 1) - Position[i],red,green,blue); // <-- changed this line
          }
          
          showStrip();
          setAll(0,0,0);
        }
      }

      Only one line did get changed, where we simply flip the LED order by subtracting the original position from the total number of LEDs.
      So position 0 becomes 15-0=15, position 1 becomes 15-1=14, position 2 becomes 15-2=13, etc.
      The “-1” is added since we count 15 LEDs, but we humans start counting with “1” where as the LED array starts counting with “0”.
      So the 15th LED actually is position 14 in the LED array in the code.

      Hope this helps! 

      Reply

      hans

      • Nov 10, 2017 - 7:31 AM - fred49 Comment Link

        Hi Hans

        You are too strong in programming, it works perfectly with my 3 colors. Thanks again and again.

        You facilitate the wiring of my garland.

        I am ready for chrismast

        thank you

        Reply

        fred49

        • Nov 11, 2017 - 3:00 PM - hans - Author: Comment Link

          Thanks Fred49!

          Glad to hear it worked out for you. Just in case you post a YouTube video or something like that; then please feel free to share the link here as well. Always cool to see what other people do! 

          A little early, but Merry Christmas for you guys! 

          Reply

          hans

          • Dec 1, 2017 - 5:36 PM - FRED49 Comment Link

            Hi !

            This is my video of my project :

            https://youtu.be/edxAOdJKeIg

            Is it possible to desynchronize my three ramps relative to each other ?


            thanks

            Have a good day

            FRED49

          • Dec 2, 2017 - 5:49 PM - hans - Author: Comment Link

            Wow that looks cool!

            I’m not sure about the code you’ve used, but per strand you could change one of these variables;

            float Gravity = -9.81;
            int StartHeight = 1;
            float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );

            I’d play with them and see what the effect is.
            I’m not quite sure what you mean with desynchronize but I assume you mean: so they don’t look too much alike.

            another place to look to make different for each strand:
              for (int i = 0 ; i < BallCount ; i++) {   
                ClockTimeSinceLastBounce[i] = millis();
                Height[i] = StartHeight;
                Position[i] = 0; 
                ImpactVelocity[i] = ImpactVelocityStart;
                TimeSinceLastBounce[i] = 0;
                Dampening[i] = 0.90 - float(i)/pow(BallCount,2); 
              }

            You could modify the calculation for “Dampening[i]” … say change 0.90 to 0.50 or 1.0. 
            Either way I have not tested, but you should be able to mimic or trigger different behavior.

            Of course the values have to be different per strand, so I’d probably start with testing which gives you the desired effect and the use the value used for that as a parameter to pass to the function.

            hans

          • Dec 8, 2017 - 12:36 PM - fred49 Comment Link

            Hi !
            Thanks for all
            in fact , this is my program i use :

            #include <Adafruit_NeoPixel.h>

            Adafruit_NeoPixel stripa = Adafruit_NeoPixel(NUM_LEDS, 5 , NEO_GRB + NEO_KHZ800);
            Adafruit_NeoPixel stripb = Adafruit_NeoPixel(NUM_LEDS, 6 , NEO_GRB + NEO_KHZ800);
            Adafruit_NeoPixel stripc = Adafruit_NeoPixel(NUM_LEDS, 4 , NEO_GRB + NEO_KHZ800);

            void setup() {
            stripa.begin();
            stripb.begin();
            stripc.begin();

            stripa.show(); // Initialize all pixels to 'off'
            stripb.show(); // Initialize all pixels to 'off'
            stripc.show(); // Initialize all pixels to 'off'
            }

            // *** REPLACE FROM HERE *** https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
            void loop() {
            byte colors[5][3] = { {0xff, 0,0}, // red

            {0, 0xff, 0}, // green

            {0, 0, 0xff}, // blue

            {0xff, 0xff, 0xff},// white

            {0xff, 0xff, 0} }; // yellow


            BouncingColoredBalls(4, colors);
            }

            void BouncingColoredBalls(int BallCount, byte colors[][3]) {
            float Gravity = -9.81;
            int StartHeight = 3; // Vitesse

            float Height[BallCount];
            float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
            float ImpactVelocity[BallCount];
            float TimeSinceLastBounce[BallCount];
            int Position[BallCount];
            long ClockTimeSinceLastBounce[BallCount];
            float Dampening[BallCount];

            for (int i = 0 ; i < BallCount ; i++) {
            ClockTimeSinceLastBounce[i] = millis();
            Height[i] = StartHeight;
            Position[i] = 0;
            ImpactVelocity[i] = ImpactVelocityStart;
            TimeSinceLastBounce[i] = 0;
            Dampening[i] = 0.90 - float(i)/pow(BallCount,2);
            }

            while (true) {
            for (int i = 0 ; i < BallCount ; i++) {
            TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
            Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;

            if ( Height[i] < 0 ) {
            Height[i] = 0;
            ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
            ClockTimeSinceLastBounce[i] = millis();

            if ( ImpactVelocity[i] < 0.01 ) {
            ImpactVelocity[i] = ImpactVelocityStart;
            }
            }
            Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
            }

            for (int i = 0 ; i < BallCount ; i++) {
            setPixel((NUM_LEDS - 1) - Position[i],colors[i][0],colors[i][1],colors[i][2]);
            }

            showStrip();
            setAll(0,0,0);
            }
            }

            void showStrip() {
            #ifdef ADAFRUIT_NEOPIXEL_H
            // NeoPixel
            stripa.show();
            stripb.show();
            stripc.show();
            #endif
            #ifndef ADAFRUIT_NEOPIXEL_H
            // FastLED
            FastLED.show();
            #endif
            }

            void setPixel(int Pixel, byte red, byte green, byte blue) {
            #ifdef ADAFRUIT_NEOPIXEL_H
            // NeoPixel
            stripa.setPixelColor(Pixel, stripa.Color(red, green, blue));
            stripb.setPixelColor(Pixel, stripb.Color(green, blue, red));
            stripc.setPixelColor(Pixel, stripc.Color(blue, red, green));
            #endif
            #ifndef ADAFRUIT_NEOPIXEL_H
            // FastLED
            leds[Pixel].r = red;
            leds[Pixel].g = green;
            leds[Pixel].b = blue;
            #endif
            }

            void setAll(byte red, byte green, byte blue) {
            for(int i = 0; i < NUM_LEDS; i++ ) {
            setPixel(i, red, green, blue);
            }
            showStrip();
            }

            ******************************************************************************

            I have 3 exit for my annimation.
            And I would like it to have a start shifting in time.
            To not see the balls all go up at the same time.

            No worries if you can not look at this for me, I’m doing tests for the moment to add annimation.

            thanks again
            have a good day

            fred

            fred49

          • Dec 10, 2017 - 2:57 PM - hans - Author: Comment Link

            What you could do is make the gravity value a random value – not too much different from the original of course:

            float Gravity = -9.81;

            to

            randomSeed(analogRead(0)); // improve randomness
            float Gravity = -(9 + (random(99) / 100));

            This way the “gravity” will be slightly different each time the function will be called.
            I have not tested this, but this is what I’d play with – maybe the notation of the random float can be done better. It basically adds 9 + “a random number between 0…99 divided by 100” (so we get a fraction of “1”) and after that make it a negative number, so that -9.81 is a possible outcome. Or better set -9 … -9.99 is a possible outcome.

            See also the Arduino random function and the randomSeed function.

            hans

  • Nov 6, 2017 - 4:41 AM - Dhiraj Kumar Comment Link

    I am new to Arduino. I want to add multiple sketch in one . How can I do this. As a Arduino can run only one sketch at a time. If I want to run multiple led function in one sketch then what is the solution for it? 

    Reply

    Dhiraj Kumar

    • Nov 11, 2017 - 2:35 PM - hans - Author: Comment Link

      Hi Dhiraj,

      apologies for the late reply.

      You can only run one sketch on your Arduino at a time.
      To get the multiple sketches to work, you’ll have to rewrite the code so all of it is in one single sketch.
      In this case (LED effects) you’ll have to combine them, like for example in this post.

      Reply

      hans

  • Nov 19, 2017 - 6:04 PM - Eric Comment Link

    First off, thanks for the really well written and highly nutritive tutorial.   I’m using the FadeInOut code broken up into two chunks like below. Curious as to how I can change the speed the leds fade up and down. Very new to Arduino and coding so my attempts experimenting with different values have resulted in undesired results. –E

    void FadeIn(byte red, byte green, byte blue){  float r, g, b;  for(int k = 0; k < 256; k=k+1) {     r = (k/256.0)*red;    g = (k/256.0)*green;    b = (k/256.0)*blue;    setAll(r,g,b);    showStrip();  }}
    void FadeOut(byte red, byte green, byte blue){  float r, g, b;    for(int k = 255; k >= 0; k=k-2) {    r = (k/256.0)*red;    g = (k/256.0)*green;    b = (k/256.0)*blue;    setAll(r,g,b);    showStrip();  }}

    Reply

    Eric

    • Nov 24, 2017 - 1:31 PM - hans - Author: Comment Link

      Hi Eric,

      first off: thank you very much for the compliment, it’s much appreciated! 

      As for changing speed, the procedure you use is pretty much at the max of it’s speed.
      We can delay it though by adding delays in the loops, for example by using the delay() function. Of course it would be nice to be able to pass the “delay” value in the function, so I modified the functions a little bit to accommodate that. The delayvalue is expressed in milliseconds (1 second = 1,000 milliseconds).

      void FadeIn(byte red, byte green, byte blue, int delayvalue) // added the delayvalue parameter
      {
        float r, g, b;
        for(int k = 0; k < 256; k=k+1) {
          r = (k/256.0)*red;
          g = (k/256.0)*green;
          b = (k/256.0)*blue;
          setAll(r,g,b);
          showStrip();
          delay(delayvalue); // <-- here we add the delay
        }
      }
      void FadeOut(byte red, byte green, byte blue, int delayvalue) // added the delayvalue parameter { float r, g, b; for(int k = 255; k >= 0; k=k-2) { r = (k/256.0)*red; g = (k/256.0)*green; b = (k/256.0)*blue; setAll(r,g,b); showStrip(); delay(delayvalue); // <-- and here again } }

      So basically when a color changes, we apply (setAll) and show (ShowStrip) it, and right after that we wait an x number of milliseconds.

      Is this what you’re looking for?

      Reply

      hans

      • Nov 24, 2017 - 5:31 PM - eric Comment Link

        If I’m understanding correctly that would add a delay between the fade up and fade down. What I would like to do is slow down the time it takes for the Led to go from black to the desired brightness level and correspondingly light to dark. I’m using the code in a motion activated light sensing night light. So, fading on and off slowly is what I’m after.

        Cheers!

        Reply

        eric

      • Nov 25, 2017 - 3:31 PM - hans - Author: Comment Link

        Hi Eric,

        No this would add a delay between each color “step”, effectively making the transition slower. So FadeIn and FadeOut would be slower, depending on the value you pass for “delayvalue”. Give it a try. DelayValue-0 is the same as the original speed. DelayValue=1000 will make it that the fade will take about 255 seconds (dee the “for” loop).

        Reply

        hans

        • Dec 2, 2017 - 7:45 PM - eric Comment Link

          Tried adding DelayValue=x and got errors. Mind showing how you would use it and why it causes the speed change. Thanks Hans!!

          void FadeIn(byte red, byte green, byte blue){
            float r, g, b;
            for(int k = 0; k < 256; k=k+1) { 
              r = (k/256.0)*red;
              g = (k/256.0)*green;
              b = (k/256.0)*blue;
              setAll(r,g,b);
              showStrip();
            }
          }

          Code below where I’m calling FadeIn

          void loop() {
            if (analogRead(lightPin) < threshold && (digitalRead(pirPin) == HIGH)) {
              if (lockLow) {
                
                //makes sure we wait for a transition to LOW before any further output is made:
                lockLow = false;
                Serial.println("---");
                Serial.print("motion detected at ");
                Serial.print(millis() / 1000);
                Serial.println(" sec");
                Serial.println(analogRead(lightPin));
                FadeIn(0xff, 0x00, 0x00); //Wait until Serial print work is done before activating strip
                delay(50);
              }
              takeLowTime = true;
            }
          Reply

          eric

          • Dec 3, 2017 - 3:14 PM - hans - Author: Comment Link

            Hi Eric,

            what error messages did you get? Did you use the code I gave?
            if so, calling FadeIn or FadeOut would be something like this:

            FadeIn(0xff, 0x00, 0x00, 1000); // one color gradation step per second

            or

            FadeIn(0xff, 0x00, 0x00, 100); // one color gradation step per 100 milliseconds

            hans

          • Dec 4, 2017 - 9:49 PM - eric Comment Link

            Thanks Hans, that led me to the solution after a little experimenting which is better than being given the answer! Now it fades as slowly as I like. 

             What I ended up changing:(in Bold)
            1) adding a delay value to the RGB values where I’m calling FadeIn and FadeOut

            2) adding “uint8_t wait” to method header

            3) and finally “delay(wait);” after strip.show() which finally pushes the change to the strip 

            FadeIn(0xff, 0x00, 0x00, 5);
            FadeOut(0xff, 0x00, 0x00, 5);
            void FadeIn(byte red, byte green, byte blue, uint8_t wait) {
              float r, g, b;
              for (int k = 0; k < 256; k = k + 1) {
                r = (k / 256.0) * red;
                g = (k / 256.0) * green;
                b = (k / 256.0) * blue;
                setAll(r, g, b);
                strip.show();
                delay(wait);
              }
            }

            eric

          • Dec 8, 2017 - 10:18 AM - hans - Author: Comment Link

            Well done Eric! Thanks for posting it here! 

            And yes; the best way to learn is to play with it yourself, but sometimes a nudge in the right direction helps right? 

            hans

  • Nov 20, 2017 - 4:46 PM - Systembolaget Comment Link

    Thanks for your easy to follow no-nonsense explanations, very straightforward to follow.

    I want to build some hanging outdoor Christmas decoration with my children (to get them interested in electronics and coding), using either Adafruit DotStar LED strip APA102 144LEDs/m or Adafruit NeoPixel RGBW 144LEDs/m and a 5V DC Trinket Pro (small size, easy to waterproof). I want to drive three two-metre strips independently (same effect, but different velocity/randomness). Does this mean I need three 5V DC PSUs and three Adafruit Trinkets? Or is there an alternative solution to drive three strips independently but from a single larger/more capable microcontroller?

    On another note – what is the limit of the length of cable if one wants to keep the microcontroller and the LED strips at a distance, say, four metres?

    Thanks in advance for some hints!

    Reply

    Systembolaget

    • Nov 24, 2017 - 1:56 PM - hans - Author: Comment Link

      Hi Systembolaget,

      Thanks for the compliment – it’s much appreciated.

      Well, the easiest would indeed be with 3 Trinkets yet. 
      Two major challenges might be, when using just one, are:
      1) Addressing the LEDs in 3 blocks, but with some coding tricks that might not be the hardest part.
      2) Having the effects on the 3 “strips” behave indecently. Arduino’s are usually not use in a multi-task setup, so they usually do things in sequence. Again, with so code skills you could consider using interrupts, but I’m sure that would make it difficult and possible undermine the enthusiasm of your kids.

      As for the length, I assume you mean the wires between Arduino and strip; 4 meters might work just fine. It will be a matter of testing, but I wouldn’t expect any issues. 

      Hope this helps!

      Reply

      hans

      • Nov 27, 2017 - 1:00 PM - Systembolaget Comment Link

        Ok, thanks for your input! I bought:

        • 3 x Adafruit Trinket Pro microcontrollers
        • 3 x Mean Well IRM-60-5ST 5V 10A PSUs
        • 3 x RND 455-00135 IP67 enclosures
        • 6 x cable glands IP67
        • 3 x APA102C 144 LED/m strips
        • Reels of colour coded silicone cables

        The PSU and Trinket will go in the enclosure to withstand the winter weather. We can’t wait for the parts to arrive. With the help of your forum here, we hope to get the coding just right.

        Reply

        Systembolaget

      • Nov 27, 2017 - 4:03 PM - Systembolaget Comment Link

        Looking at the latest FastLED git, it seems that one can drive multiple strips doing different things https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples

        However, I will stick to three independent setups to not overload the kids.

        Reply

        Systembolaget

      • Dec 2, 2017 - 5:06 PM - hans - Author: Comment Link

        Sounds like you’re ready for a cool project – your kids will love it! 
        And you’re right, don’t want to make it too complicated, otherwise they’ll loose interest and that would be a shame.
        Keep us posted on the progress! 

        Reply

        hans

  • Dec 3, 2017 - 5:41 AM - Dai Comment Link

    Hi again,

    I found this page while googling other led animation stuff led animations and thought it would be useful to others to know a way to have their arduino’s use a non-blocking method to display animations. I am using this to allow a button press to change animations (in progress) and so far it looks very promising. I haven’t had time to convert any of your animations yet (but I’m sure to try soon) but I do think it would work with a little tweaking.

    Here is a code snippet example showing both ways to code the same display, I’m not sure if either are the best way to do this but it’s code I am trying at the moment.

    NON-BLOCKING METHOD

    #include<FastLED.h>
    #define NUM_LEDS 14
    int i = 0;
    CRGBArray<NUM_LEDS> leds;

    void setup() { FastLED.addLeds<NEOPIXEL,6>(leds, NUM_LEDS); }

    void loop(){
    static uint8_t hue;
    EVERY_N_MILLISECONDS(200){
    leds.fadeToBlackBy(180);
    if (i<NUM_LEDS/2){
    leds[i] = CHSV(hue++,255,255);
    i++;
    }else{
    i=0;
    }
    leds(NUM_LEDS/2,NUM_LEDS-1) = leds(NUM_LEDS/2 - 1 ,0);
    FastLED.show();
    }
    }

    NORMAL METHOD (using delay)

    #include<FastLED.h>
    #define NUM_LEDS 14

    CRGBArray<NUM_LEDS> leds;

    void setup() { FastLED.addLeds<NEOPIXEL,6>(leds, NUM_LEDS); }

    void loop(){
    static uint8_t hue;
    for(int i = 0; i < NUM_LEDS/2; i++) {
    leds.fadeToBlackBy(180);
    leds[i] = CHSV(hue++,255,255);
    leds(NUM_LEDS/2,NUM_LEDS-1) = leds(NUM_LEDS/2 - 1 ,0);
    FastLED.delay(200);
    }
    }

    Both of these move a trail of pixels from outside edge to the middle, but the non-blocking method allows the arduino to do other stuff in between (like checking sensors, reading button presses etc).

    Anyway I hope it is useful to someone else and thanks again for the inspiration gained from this site.

    Reply

    Dai

    • Dec 3, 2017 - 3:26 PM - hans - Author: Comment Link

      Thanks Dia!

      Your info is much appreciated – great tip! – and I’m sure users will have benefit from it! Awesome, thanks! 

      Reply

      hans

  • Dec 5, 2017 - 1:02 AM - Trinitor - Author: Comment Link

    Hi,

    thanks for your great examples. 

    I went a different route in my project by using the strip as receiver and define the content on a different machine.

    The controller opens an UDP port and accepts commands in a json format as input.

    https://wiki.d.evba.se/doku.php?id=projects:neopixel-bandwidth-room-light

    Your effects should be fairly easy to be added to this structure so you can trigger them over Wifi.

    I hope you enjoy it and I helps others to come up with some ideas.

    Cheers

    Reply

    Trinitor

    • Dec 7, 2017 - 4:46 PM - Dai Comment Link

      That’s a pretty cool project, I’ve bookmarked it for when I get my ESP8266! I’m currently using arduino pro minis for my strings as they are cheap and can control around 600 (ish) pixels depending on the code, but I think the ESP8266 has more possibilities. I might try adjusting your code to see if I can get an Arduino Mega with ethernet board working with it. I like to code in python and think if I get this working it would mean I could use some scripting to get all the effects I could possibly need (for now anyway :) ) Thanks for posting this.

      Reply

      Dai

    • Dec 8, 2017 - 10:23 AM - hans - Author: Comment Link

      Thanks – I’ve listed this for my ESP8266 future projects as well 

      Reply

      hans

      • Apr 4, 2018 - 1:23 PM - Mike Garber Comment Link

        Be advised that the fastPixel library has problems with the 8266, but the neo seems fine.

        Reply

        Mike Garber

        • Apr 6, 2018 - 2:22 AM - hans - Author: Comment Link

          Thanks Mike for the heads up!
          Others will most definitely benefit from it! 

          I still have to get started with the ESP8266, hopefully by then FastLED will be updated 

          Reply

          hans

  • Dec 12, 2017 - 6:09 AM - Dai Comment Link

    I’ve been playing around with some different effects for a few strings of NEOPIXELS running on an Arduino Pro Mini and have found that theatreChaseRainbow function will prevent any further effects being displayed. I have adjusted my effects to put this one last and it works for now but I must put it last in the list and have also noticed that the millis() count is reset to Zero after this effect finishes. I don’t know if this is possibly a memory limit reached causing a reset or something like that but thought I would post in case somebody had noticed (and maybe fixed) it.

    The code I am using for this strip is :-

    #include "FastLED.h"
    #define NUM_LEDS 14
    #define DATA_PIN 6
    CRGB leds[NUM_LEDS];

    void setup() {
    Serial.begin(9600);
    LEDS.addLeds<NEOPIXEL,DATA_PIN>(leds,NUM_LEDS);
    LEDS.setBrightness(255);
    }

    void loop() {
    // Serial.print(millis());
    // Serial.print(" - ");
    Serial.print(millis());
    Serial.println(" in_out");
    for (int i=0;i<5;i++){ // 180 Seconds
    in_out(142); // 36 Seconds
    }
    Serial.print(millis());
    Serial.println(" Sparkle");
    for(int count=0;count<900;count++){ // 180 Seconds
    Sparkle(random(255),random(255),random(60),200); // 0.2 Seconds per pixel
    }
    Serial.print(millis());
    Serial.println(" FadeInOut");
    for(int count=0;count<20;count++){
    FadeInOut(random(255),random(255),random(255),20); // 177 Seconds
    }
    Serial.print(millis());
    Serial.println(" TwinkleRandom");
    TwinkleRandom(1800,100,false); // [181] 1 Second per 10 count (first parameter)
    Serial.print(millis());
    Serial.println(" theatreChaseRainbow");
    theaterChaseRainbow(230); // 177 Seconds
    Serial.println(millis());
    }

    void in_out(int SpeedDelay){
    byte *c;
    int myled1 = 0;
    int myled2 = NUM_LEDS-1;
    for (int j=0;j<252;j++){
    c = Wheel( j % 255);
    setPixel(myled1, c[0], c[1], c[2]);
    setPixel(myled2, c[0], c[1], c[2]);
    if(myled1<NUM_LEDS-1){
    myled1++;
    myled2--;
    }else{
    myled1 = 0;
    myled2 = NUM_LEDS-1;
    }
    fadeall(100);
    FastLED.show();
    delay(SpeedDelay);
    }
    }

    void theaterChaseRainbow(int SpeedDelay) {
    byte *c;
    for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
    for (int i=0; i < NUM_LEDS; i=i+3) {
    c = Wheel( (i+j) % 255);
    setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on
    }
    showStrip();
    delay(SpeedDelay);
    for (int i=0; i < NUM_LEDS; i=i+3) {
    setPixel(i+q, 0,0,0); //turn every third pixel off
    }
    }
    }
    }

    void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
    int Pixel = random(NUM_LEDS);
    setPixel(Pixel,red,green,blue);
    showStrip();
    delay(SpeedDelay);
    setPixel(Pixel,0,0,0);
    }

    void FadeInOut(byte red, byte green, byte blue, int timer){
    float r, g, b;
    for(int k = 0; k < 256; k=k+1) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
    delay(timer);
    }
    for(int k = 255; k >= 0; k=k-2) {
    r = (k/256.0)*red;
    g = (k/256.0)*green;
    b = (k/256.0)*blue;
    setAll(r,g,b);
    showStrip();
    delay(timer);
    }
    }

    void TwinkleRandom(int Count, int SpeedDelay, boolean OnlyOne) {
    setAll(0,0,0);
    for (int i=0; i<Count; i++) {
    fadeall(150);
    setPixel(random(NUM_LEDS),random(0,255),random(0,192),random(0,128));
    showStrip();
    delay(SpeedDelay);
    if(OnlyOne) {
    setAll(0,0,0);
    }
    }
    // delay(SpeedDelay);
    }

    byte * Wheel(byte WheelPos) {
    static byte c[3];
    if(WheelPos < 85) {
    c[0]=WheelPos * 3;
    c[1]=255 - WheelPos * 3;
    c[2]=0;
    } else if(WheelPos < 170) {
    WheelPos -= 85;
    c[0]=255 - WheelPos * 3;
    c[1]=0;
    c[2]=WheelPos * 3;
    } else {
    WheelPos -= 170;
    c[0]=0;
    c[1]=WheelPos * 3;
    c[2]=255 - WheelPos * 3;
    }
    return c;
    }

    void setPixel(int Pixel, byte red, byte green, byte blue) {
    leds[Pixel].r = red;
    leds[Pixel].g = green;
    leds[Pixel].b = blue;
    }

    void setAll(byte red, byte green, byte blue) {
    for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
    }
    showStrip();
    }

    void showStrip() {
    FastLED.show();
    }

    void fadeall(int scale) { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(scale); } }

    And the Serial output I get is :-

    0 in_out
    
    179646 Sparkle
    360445 FadeInOut
    537857 TwinkleRandom
    719520 theatreChaseRainbow
    1 in_out
    179646 Sparkle
    360445 FadeInOut
    537857 TwinkleRandom
    719520 theatreChaseRainbow
    1 in_out
    179646 Sparkle

    If I comment out the theatreChaseRainbow effect then the millis() count is normal (keeps adding after each cycle). Any body have any ideas?

    Also what I haven’t shown here is if you put the theatreChaseRainbow in the middle of the list it will display the effects before it but then resets after it and the following effects do not show (it starts from the beginning again without completing the main loop)

    Reply

    Dai

    • Dec 13, 2017 - 3:33 PM - hans - Author: Comment Link

      Hi Dai,

      I couldn’t find anything weird that might trigger these issues.
      millis() will not reset until it has run for about 50 days (according to the documentation).
      Resetting the clock used by millis() isn’t even that easy (see this post).

      So now I’m left guess, and what might do the trick is where you use “NUM_LEDS”, and use “NUM_LEDS-1” instead, so try the theaterChaseRainbow with this code (I changed 2 lines):

      void theaterChaseRainbow(int SpeedDelay) {
        byte *c;
        
        for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
          for (int q=0; q < 3; q++) {
              for (int i=0; i < NUM_LEDS-1; i=i+3) { // <-- change here
                c = Wheel( (i+j) % 255);
                setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on
              }
              showStrip();
             
              delay(SpeedDelay);
             
              for (int i=0; i < NUM_LEDS-1; i=i+3) { // <-- change here
                setPixel(i+q, 0,0,0); //turn every third pixel off
              }
          }
        }
      }

      Maybe not exactly the correct programmers way to do this, but worth a test.

      Reply

      hans

      • Dec 13, 2017 - 4:15 PM - Dai Comment Link

        Thank you Hans, that has worked on a small test with only three effects, but when i put the full script in place it seems to go back to previous behaviour (resetting the millis count and starting from the beginning…) I am guessing at this point that there would be a memory full error which might cause a reset because it is not happening when I use less effects, but thank you for trying and I might have to reduce the number of effects for these strings or I might use another method to get similar effect.

        Reply

        Dai

      • Dec 14, 2017 - 3:47 PM - hans - Author: Comment Link

        Erratic behavior could indeed be caused by out-of-memory (see this document).

        This still happens when you change the order of the effect (ie. start with theaterChaseRainbow() and run the other effects after that)?

        Reply

        hans

        • Dec 15, 2017 - 3:15 PM - Dai Comment Link

          Yes, I think it is a simple out of memory error, and thanks to your link I may be able to fix it using PROGMEM for some fixed variables, although I will have to come back to it when I’ve finished a few other bits .

          I did try with theaterChase Rainbow at the beginning and the results are the same, that is, if I only have one (or maybe two) other effects it works as expected, but if I have more effects (and the associated Serial.print statements that I’m using for tests) then theaterChaseRainbow will trigger a restart (not directly but because of the memory issue). So I’m sure that it can be overcome with a little coding change on my part.

          Thanks for the great help and advice, it is much appreciated

          Reply

          Dai

          • Dec 17, 2017 - 12:09 PM - Dai Comment Link

            I thought I had better post the solution to my particular problem in case it might be of use to others with a similar issue, I decided to try and “shorten” or “shrinkify” the theaterChaseRainbow sketch and this is what I ended up with :-

            void theaterChaseRainbow(int SpeedDelay) {
            for (int j=0; j<256; j++) {
            for (int q=0; q<3; q++) {
            for (int i=2; i<NUM_LEDS-2; i=i+3) {
            c = Wheel(j);
            setPixel(i+q, *c, *(c+1), *(c+2));
            }
            showStrip();
            fadeall(15);
            delay(SpeedDelay);
            }
            }
            }

            This makes use of the fadeall function I am using in another sketch to turn off the lights after they have been displayed, it can be set differently to have the lights go off almost immediately to make the pattern more like the original one you (Hans) posted. 

            Anyway, everything is working as it should and I am again a happy bunny  

            Thanks again for your advise/inspiration.

            Dai

          • Dec 17, 2017 - 4:41 PM - hans - Author: Comment Link

            Hi Dai!

            Great to hear you’re happy with the result and thanks for posting your function! 

            hans

  • Dec 13, 2017 - 7:03 AM - Systembolaget Comment Link

    We got our setup (Pro Trinket 5V and APA102C 144 LEDs/m strip) working and are now wondering how we could achieve something along the monochromatic/polychromatic “twinkle” or “sparkle” effects shown above, but more subtle and continuous, also taking into account that the brightness of LEDs should fade in/out sinusoidal or, rather, logarithmic (human brightness perception)?
    Here’s one code-less example of “random twinkling” that shows what we’re after… do you have some ideas how that could be done?
    Thanks for some hints!

    Reply

    Systembolaget

    • Dec 13, 2017 - 3:38 PM - hans - Author: Comment Link

      Hi Systembolaget,

      that’s good news! 

      As for the desired effect; I like the idea, but I have not code readily available to do this.
      i’d have to sit down and set everything up to do some testing to see what works best.
      Unfortunately, I do not have my gear readily available so it would take quite some time before I’d have code available … 

      Reply

      hans

      • Dec 13, 2017 - 4:32 PM - Dai Comment Link

        Hi Systembolaget,

        You could try this sketch I think it goes some way towards what you want, it uses the TwinkleRandom sketch with some minor modifications, you can enter the fade speed using the extra parameter I added. You will probably need a longer fade value for longer strings as I have only been using this on a 14 pixel string at the moment. Also this doesn’t fade pixels in but does fade them out. Hope this helps towards finding something useful.

        #include "FastLED.h"
        #define NUM_LEDS 14
        #define DATA_PIN 6
        CRGB leds[NUM_LEDS];


        void setup() {
        Serial.begin(9600);
        LEDS.addLeds<NEOPIXEL,DATA_PIN>(leds,NUM_LEDS);
        }

        void loop(){
        // put your main code here, to run repeatedly:
        TwinkleRandom(1800,100,150,false);
        }

        void TwinkleRandom(int Count, int SpeedDelay, int fadespeed, boolean OnlyOne) {
        setAll(0,0,0);
        for (int i=0; i<Count; i++) {
        fadeall(fadespeed);
        setPixel(random(NUM_LEDS),random(0,255),random(0,192),random(0,128));
        showStrip();
        delay(SpeedDelay);
        if(OnlyOne) {
        setAll(0,0,0);
        }
        }
        // delay(SpeedDelay);
        }

        void setPixel(int Pixel, byte red, byte green, byte blue) {
        leds[Pixel].r = red;
        leds[Pixel].g = green;
        leds[Pixel].b = blue;
        }

        void setAll(byte red, byte green, byte blue) {
        for(int i = 0; i < NUM_LEDS; i++ ) {
        setPixel(i, red, green, blue);
        }
        showStrip();
        }

        void showStrip() {
        FastLED.show();
        }

        void fadeall(int scale) { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(scale); } }

        Reply

        Dai

      • Dec 16, 2017 - 5:01 PM - Systembolaget Comment Link

        Hej Hans,

        after going through the FastLED 3.1 codebase on Github, I found a good solution, which is nicely twinkling, glittering or sparkling; maybe useful for others, too.

        /*
         * 
         * Glitter adapted from Mark Kriegsman's FastLED demo reel
         * 
         */

        #include "FastLED.h"

        #define LED_DATA 3 // Data pin
        #define LED_CLOCK 4 // Clock pin
        #define COLOR_ORDER BGR // GRB for WS2812 and BGR for APA102
        #define LED_TYPE APA102 // Using APA102, WS2812, WS2801 - don't forget to adapt "LEDS.addLeds..."
        #define NUM_LEDS 144uint8_t max_bright = 231; // Overall brightness definition
        struct CRGB leds[NUM_LEDS]; // Initialize LED array

        void setup() {
          
          delay(1000); // Soft start
          
          LEDS.addLeds<LED_TYPE, LED_DATA, LED_CLOCK, COLOR_ORDER>(leds, NUM_LEDS); // For WS2801 or APA102
          
          FastLED.setBrightness(max_bright);
          
        }

        void loop() {
          fadeToBlackBy( leds, NUM_LEDS, 1); //third variable determines how quickly the LEDs fade
          addGlitter(32); //changing this variable will increase the chance of a new "star" popping up
          FastLED.show();
          
        }

        void addGlitter( fract8 chanceOfGlitter) {
          if( random8() < chanceOfGlitter) {
            leds[ random16(NUM_LEDS) ] += CRGB::White;}
        }
        Reply

        Systembolaget

        • Dec 17, 2017 - 4:59 PM - hans - Author: Comment Link

          Awesome! Thanks Systembolaget for posting this!! 

          Reply

          hans

          • Dec 18, 2017 - 6:05 PM - Systembolaget Comment Link

            This subtle change allows for hue, saturation and brightness control. Randomised or clamped to a range. Enjoy!

            /*
             * 
             * Glitter (?) https://gist.github.com/mock-turtle/d59716ab96dca6c8ec0b
             * 
             */

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

            // Fixed definitions. Cannot be changed interactively
            #define LED_DATA 3 // Data pin
            #define LED_CLOCK 4 // Clock pin
            #define COLOR_ORDER BGR // 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 144 // Number of LEDs

            // Global variables. Can be changed interactively
            uint8_t max_bright = 128; // Overall brightness
            uint8_t hue = 0;

            struct CRGB leds[NUM_LEDS]; // Initialise LED array

            void setup() {
              
              delay(1000);
              
              LEDS.addLeds<LED_TYPE, LED_DATA, LED_CLOCK, COLOR_ORDER>(leds, NUM_LEDS); // For WS2801 or APA102
              
              FastLED.setBrightness(max_bright);
              
            }

            void loop() {
              fadeToBlackBy( leds, NUM_LEDS, 1); // Third variable determines how quickly the LEDs fade
              addGlitter(37); // Changing the number will increase the chance of a "star" popping up
              FastLED.show();
              
            }

            void addGlitter( fract8 chanceOfGlitter) {
              if( random8() < chanceOfGlitter) {
                //leds[ random16(NUM_LEDS) ] += CRGB::Snow;} // Glitter colour fixed
                leds[ random16(NUM_LEDS) ] += CHSV(random8(192,255), 255, random8(64,255));} // Glitter colour hue and brightness randomised in a range
            }

            Systembolaget

          • Dec 21, 2017 - 9:32 AM - hans - Author: Comment Link

            Nice! You’re having fun with the LED strips, aren’t you? (me too!)
            Thanks again for posting your code! 

            hans

  • Dec 21, 2017 - 2:33 PM - Daniel Comment Link

    Hello, and thank you very much for this very impressive Effects!

    Never found a site with this much of exaples!

    I want to use all effects by calling them in the main loop(), all is working ok but the effect:

    “Bouncing Balls” is running and never ends :-(

    In that effect there is this codepart:

    while(true)

    while WHAT is true ?

    So please can someone tell me how i can stopp the effect after one time running?

    I want to change the Ballcolor after each run, so i want to call the function this way:

    void loop()
    {BouncingBalls(255,0,0, 1); //RGB-Color, Balls - only 1x runnung
    BouncingBalls(0,255,0, 1); //RGB-Color, Balls - only 1x running
    BouncingBalls(0,0,255, 1); //RGB-Color, Balls - only 1x running
    }
    Reply

    Daniel

    • Dec 23, 2017 - 11:15 AM - hans - Author: Comment Link

      Hi Daniel,

      thank you for the compliment! 

      As for the “while(true)” – this keeps the loop going until the end of time (unless power gets disrupted of course. 
      I did this to avoid having to look for an elegant exit.
      To change that you’d have to change the while-loop.

        while (true) {
          for (int i = 0 ; i < BallCount ; i++) {
            TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
            Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
        
            if ( Height[i] < 0 ) {                      
              Height[i] = 0;
              ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
              ClockTimeSinceLastBounce[i] = millis();
        
              if ( ImpactVelocity[i] < 0.01 ) {
                ImpactVelocity[i] = ImpactVelocityStart;
              }
            }
            Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
          }
        
          for (int i = 0 ; i < BallCount ; i++) {
            setPixel(Position[i],red,green,blue);
          }
          
          showStrip();
          setAll(0,0,0);
        }

      to (for example – i don’t think this is very elegant):

        for(int count=0; count<100; count++) {
          for (int i = 0 ; i < BallCount ; i++) {
            TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
            Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
        
            if ( Height[i] < 0 ) {                      
              Height[i] = 0;
              ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
              ClockTimeSinceLastBounce[i] = millis();
        
              if ( ImpactVelocity[i] < 0.01 ) {
                ImpactVelocity[i] = ImpactVelocityStart;
              }
            }
            Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
          }
        
          for (int i = 0 ; i < BallCount ; i++) {
            setPixel(Position[i],red,green,blue);
          }
          
          showStrip();
          setAll(0,0,0);
        }

      This will make the balls do 100 “steps”.
      To make it more elegant, untested though, you could try to make the balls stop once they do not bounce beyond a certain height;

        boolean started=false; // to avoid that we stop too early
        boolean canstop=false; // once this is true, and started=true, we can stop and exit the loop
        
        while (!canstop) {  // while not canstop
          for (int i = 0 ; i < BallCount ; i++) {
            TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
            Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
        
            if ( Height[i] < 0 ) {                      
              Height[i] = 0;
              ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
              ClockTimeSinceLastBounce[i] = millis();
        
              if ( ImpactVelocity[i] < 0.01 ) {
                ImpactVelocity[i] = ImpactVelocityStart;
              }
            }
            Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
          }
        
          for (int i = 0 ; i < BallCount ; i++) {
            setPixel(Position[i],red,green,blue); started = started || Position[i]>4; // arbitrary number (4) - depends a little on the length of your LED strip canstop = (Position[i]<3) && started; // did we start? and did a ball go below 2? Then we exit the loop
          }
          
          showStrip();
          setAll(0,0,0);
        }

      The idea being; if one of the balls has passed a position higher than LED #4 then we set “started” to true (meaning; we can now start looking for when a ball goes below LED #3). “canstop” will become true when “started” is true AND we found a ball below LED #3.
      Again the numbers 3 and 4 are arbitrary chosen, you’ll have to play with that to see what value works for you.

      Hope this will get you started – feel free to ask questions and/or share your findings.

      Reply

      hans

      • Dec 23, 2017 - 9:36 PM - Daniel Comment Link

        Hello Hans and first of all Vrolijk Kerstfeest to you and your family!

        I really try your second implementation but it is not working here with my 60 led strip.

        It stars with red ball, red i flying to top, after red goes to 0, green starts to top and after

        reaching 0, the blue ball stops – so there is only one jumping per ball!

        I have a idee: when the Ball is about to die, he stays a longer time on StripLED 0 for around 1 second, so i try

        to stop the function at this position, but i’m really not good in programming inside a arduino loop().

        void setup()
        {BouncingBalls(255,0,0, 1); //RGB-Color, Balls
        BouncingBalls(0,255,0, 1); //RGB-Color, Balls
        BouncingBalls(0,0,255, 1); //RGB-Color, Balls
        }


        ...
        ...
        for(int i=0; i<BallCount; ++i)
        {setPixel(Position[i],red,green,blue);

        //Your code:
        //started=started||Position[i]>4; //arbitrary number(4), depends on the length of the LED strip
        //canstop=(Position[i]<3)&&started; //did we start? and did a ball go below 2? Then we exit the loop

        //My Idee (not working):
        unsigned long curMillis=millis();
        if(Position[i]==0 && curMillis - prevMillis > 500)
        {canstop=true;}
        prevMillis=curMillis;
        }
        Reply

        Daniel

        • Dec 25, 2017 - 4:16 PM - hans - Author: Comment Link

          Hi Daniel,

          sorry that it didn’t work as hoped – I’m a little limited since I cannot test as my hardware is nowhere near me.

          Your timer approach could work, but I do tend to write if statements with more brackets to make sure it does what is expected. So you line

          if(Position[i]==0 && curMillis - prevMillis > 500)

          I’d write as:

          if( (Position[i]==0) && (curMillis - prevMillis > 500) )

          Another thing we could do is use a counter that increase with each bounce and when a certain number has been reached; we exit.

          Something in the line of:

          ...
          int bounceCount = 0;
          ...
          if(Position[i]==0) { bounceCount++; }
          canstop = bounceCount>6;
          ...

          Hope this helps … and Merry Christmas 

          Reply

          hans

          • Dec 26, 2017 - 10:07 AM - Daniel Comment Link

            Hello Hans, i try all the ideas but nothing works really good.

            But then i checked again your code “BouncingBalls” and i found a 100% perfect

            solution :-)

            if(ImpactVelocity[i]<0.1) {canstop=true;} //Stop script
            //if(ImpactVelocity[i]<0.01) {ImpactVelocity[i]=ImpactVelocityStart;}
            //Serial.println(ImpactVelocity[i]);

            I replace only one code line from the script with this one!

            It works perfekt and stopps wenn Balljumping in lower then 0.1

            But this woes not work with the multi bouncing balls “BouncingColoredBalls”

            because in this line

            if(ImpactVelocity[i]<0.1) {canstop=true;} //Stop script

            you can not check witch of the 3 balls in in the stopping-phase….and also it looks like

            the balls are touching each other and amplify or break the jumping Gravity formula :-(

            But for now its ok with one Ball bouncing…..

            By the way your idee:

            int bounceCount=0;

            if(pos[i]==0) {++bounceCount;}
            canstop=bounceCount>6;

            is working but the >6 must be in my case around >210 for one ball because on each jump

            and fall the ball is passing 2 times the Index 0.

            But i will try to use this code for the 3 ball bouncing, by increesing the value >600.

            I will post here for others if i got success.

            Have a nice eavening Hans, great site.!

            Daniel

          • Dec 26, 2017 - 11:27 AM - hans - Author: Comment Link

            Awesome fix Daniel – can’t believe I totally overlooked that one.

            Yeah with multiple balls you’ll have a challenge.
            Maybe it would be good (with 3 balls) that a ball stops bouncing once it’s done with it’s bounce(s), until all balls are done.

              boolean canstop = false;
             
              while (!canstop) {
                for (int i = 0 ; i < BallCount ; i++) { if(ImpactVelocity[i]>0) {
                  TimeSinceLastBounce[i] = millis() - ClockTimeSinceLastBounce[i];
                  Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
              
                  if ( Height[i] < 0 ) {                      
                    Height[i] = 0;
                    ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
                    ClockTimeSinceLastBounce[i] = millis();
              
                    if ( ImpactVelocity[i] < 0.01 ) { // changes here
                      ImpactVelocity[i] = -1;
                    }
                  }
                  Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight); }
                }
              
                for (int i = 0 ; i < BallCount ; i++) { canstop = true; // start with assuming none of the balls are bouncing if(ImpactVelocity[i] > 0) { // changes here setPixel(Position[i],colors[i][0],colors[i][1],colors[i][2]); canstop = false; // still ate least one ball bouncing, so do not stop }
                }
                
                showStrip();
                setAll(0,0,0);
              }

            Since ImpactVelocity will never be below 0, we could abuse that – set it to -1 when the bounce is done.
            Not sure what the impact will be of not setting the ball … but I figured it may remain “at the bottom”?
            Again; untested, but maybe it’s helpful …

            hans

  • Dec 22, 2017 - 11:14 PM - Maike Comment Link

    Good morning! Thanks a lot for this awesome and helpful site. The toilet paper hack is my favourite 

    I used your code for my attiny85 with a WS2812 strip. A motion sensor turns the effect on and off after a short delay. Now here comes my question and it would be great if you could help me, because I want to use this for an infinity mirror as a christmas present!

    Question: Do you have an idea how to go through all effects instead of repeating only one? So, whenever the sensor detects a new motion, he does not show the previous effect but a new one. Do you think this is possible?

    Best regards from Germany 

    Reply

    Maike

    • Dec 23, 2017 - 11:30 AM - hans - Author: Comment Link

      Hi Maike!

      Thanks for the compliment and I have to agree that the toilet paper hack looks great and is kind-a funny at the same time .

      In the forum, and some posts here, show some examples on how to use multiple effects in one sketch. See for example this comment or this forum topic.

      I hope to find time soon to work on questions like this – unfortunately at this time regular work leaves me very little time to do fun projects. 

      Reply

      hans

  • Dec 24, 2017 - 10:54 PM - maike Comment Link

    Thank you very much for your answer! It worked out and my parents-in-law were very happy about their present. I used it for an infinity mirror with a motion sensor and two magnetic key holders. It was fun doing the project, so thanks for your help and sharing for knowledge 

    Enjoy Christmas!

    Reply

    maike

    • Dec 25, 2017 - 4:18 PM - hans - Author: Comment Link

      Hi Maike!

      Merry Christmas to you too! 
      Glad to hear your project worked out … actually sounds like an interesting project! 

      Reply

      hans

      • Dec 25, 2017 - 10:48 PM - maike Comment Link

        If you want to take a look at it: https://photos.app.goo.gl/CCFstrtUiKsaf4M33

        The next one will be better, but this was very good to learn all the differents tasks from cutting ikea mirrors to coding the neopixels! Thanks to your great descriptions, videos and explanations 

        Reply

        maike

      • Dec 26, 2017 - 9:10 AM - hans - Author: Comment Link

        Oh wow! that looks nice! Well done! 

        I’ll have to look into that some more as well … I like it!

        Reply

        hans

  • Dec 25, 2017 - 8:54 AM - Henrik Lauridsen Comment Link

    Hi Hans,

    Could you show an meteor rain example. Thank you in advance,

    Henrik

    Reply

    Henrik Lauridsen

    • Dec 25, 2017 - 4:19 PM - hans - Author: Comment Link

      Hi Hendrik,

      well, ehm … that depends on what a meteor shower looks like.
      Do you have an example? For example a YouTube video that shows this effect?

      Merry Christmas and a happy New Year to you too 

      Reply

      hans

      • Dec 26, 2017 - 3:23 AM - Henrik Lauridsen Comment Link

        Hi Hans,

        Thank you for your reply and wishes.

        Something like :

        Meteor rain

        https://www.youtube.com/watch?v=pCrMn_240Ms

        Meteor rain 2

        https://www.youtube.com/watch?v=i_ld7vK2tAs

        I would like to be able to change color and speed of the meteor rain.

        By the way I always comes back to this site. Great site. Thank you,

        Henrik

        Reply

        Henrik Lauridsen

        • Dec 26, 2017 - 9:51 AM - hans - Author: Comment Link

          Hi Henrik!

          Thanks for the YouTube links,… and thanks for keeping traffic on my website going, it’s very much appreciated.

          As for the code for the meteor rain; I’ll have to do some tinkering – mostly finding my Arduino and LED strips.
          It doesn’t look like this would be super complicated though.
          I’ll try to make some time this week to write some code for this, and maybe combine that with some extras to cycle through all the effects mentioned in this post.
          Might take a little though,… 

          Reply

          hans

          • Dec 26, 2017 - 9:58 AM - Henrik Lauridsen Comment Link

            Hi Hans,

            Thank you for your time.

            I am looking forward to your solution with excitement. 

            Henrik Lauridsen

          • Dec 27, 2017 - 9:11 PM - hans - Author: Comment Link

            Hi Hendrik,

            I hope you like this one; it’s currently only for one strip though.

            The function meteorRain takes 6 parameters:

            For the color of the meteor: red, green, blue

            – meteorSize: size of the meteor (including trail)

            – meteorIntensity: intensity of the trail, or how fast the trail fades (1=fast fade, 10=slow fade)

            – speedDelay: how fast the meteor moves by setting a delay value (so higher value = slower)

            I have the meteor fade all the way, so even if the meteor is out of sight (past the end of the strip) then the trail will keep going until it’s totally gone.

            // *** REPLACE FROM HERE ***
            void loop() {
              meteorRain(0xff,0xff,0xff,40,5,20);
            }
            void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorIntensity, int SpeedDelay) {
              
              for(int i = 0; i < NUM_LEDS+meteorSize; i++) {
              
                setAll(0,0,0);
                if(i<NUM_LEDS) {
                  setPixel(i, red, green, blue);
                }
                for(byte j=1; j<meteorSize; j++) {
                  if( (i-j>=0) && (i-j<NUM_LEDS) ) {
                    setPixel(i-j, red/(j/meteorIntensity), green/(j/meteorIntensity), blue/(j/meteorIntensity)); 
                  }
                }
                
                showStrip();
                delay(SpeedDelay);
              }
            }
            // *** REPLACE TO HERE ***

            Give it a shot an see what you think. I’m sure there is room for improvement (for example; dividing colors to mimic a fade is OK but can be done better).
            I did try this with a 60 LED strip and looked pretty good. Then again; I never payed much attention to the meteor rain effect in the past.

            Let me know what you think, and if it’s worthy I’ll add it to the list above – if not, then we’ll do some tweaking …

            hans

          • Dec 28, 2017 - 7:27 AM - Henrik Lauridsen Comment Link

            Hi Hans, 

            Thank you very much for your time and solution. Its looking good and in my opinion absolutely worthy to join the list above.

            Of course it would be great with an option to support more strip syncron or asyncron and a wait state before the meteor started all over. 

            Again thank you and please keep up the good work, 
            Henrik

            Henrik Lauridsen

          • Dec 30, 2017 - 4:13 AM - Systembolaget Comment Link

            Hej,

            here’s one with a sparkling and adjustable length trail. Colour can be fixed or change, too. Happy Easter!

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

            // Fixed definitions. Cannot be changed interactively
            #define LED_DATA 3 // Data pin
            #define LED_CLOCK 4 // Clock pin
            #define COLOR_ORDER BGR // 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 234 // Number of LEDs set higher than strip length to have trail vanish fully

            int head_led = 0;

            // Global variables. Can be changed interactively
            uint8_t max_bright = 32; // Overall brightness
            uint8_t tHue = 0; // the trail's hue starting point; set also if no hue change desired
            struct CRGB leds[NUM_LEDS]; // Initialise LED array

            void setup() {
              
              delay(1000);
              
              LEDS.addLeds<LED_TYPE, LED_DATA, LED_CLOCK, COLOR_ORDER>(leds, NUM_LEDS); // For WS2801 or APA102
              
              FastLED.setBrightness(max_bright);
              
            }

            void loop()
            {
              
              //EVERY_N_SECONDS(2) { tHue = tHue + 3; } // uncomment to shift hue periodically by a certain amount
              EVERY_N_MILLISECONDS(24)
              
              {
              
                fadeToBlackBy(leds, NUM_LEDS, 6); // n/256 = trail length; smaller number = longer trail
                leds[head_led] = CHSV(tHue, 96, random8(96,255)); // set hue, saturation, brightness
                
                head_led = head_led + 1; // move the head LED one position forward
                if(head_led == NUM_LEDS){ head_led = 0; }
                FastLED.show();
              
              }
              
            }

            Systembolaget

          • Dec 31, 2017 - 3:13 PM - hans - Author: Comment Link

            Thanks Hendrik!

            Glad you liked it. As for your suggestion; Hey, it wouldn’t be fun if we couldn’t improve this right? 
            The option to add more strips would of course be great, but that would no longer fit this “generic” approach I’m afraid.

            hans

          • Jan 1, 2018 - 2:30 PM - hans - Author: Comment Link

            Since I love playing with LED strips, a variant that might be better;

            This one only works with FastLED since NeoPixel has no function to fade LEDs (by my knowledge).

            I’ve added a few options like the size of the meteor (excl. tail), how fast the tail decays, if the tail LEDs should decay at random (leaving little pieces that decay less fast). Play a little with the values and to add randomness – play with random values as well.

            As for a random start when using multiple Arduino’s and/or strands;
             you could do a “delay(random(12345));” before the meteorRain() call. You’d probably need to set randomSeed() in the setup function, for example:

            void setup(){
            ...
              randomSeed(analogRead(0));
            }

            // *** REPLACE FROM HERE ***
            void loop() {
              meteorRain(0xff,0xff,0xff,10, 64, true, 30);
            }
            void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
              // red/green/blue = meteor color
              // meteorSize = #LEDs for the meteor (main part, excluding the trail)
              // meteorTrailDecay = fading speed of the trail. 64 = dim by 25% (64/256ths); lower number = longer tail
              // meteorRandomDecay = true of false. False = smooth tail, true = tail that breaks up in pieces
              // SpeedDelay = pause in ms after drawing a cycle - lower number = faster meteor
              
              setAll(0,0,0);
              
              for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
                // fade brightness all LEDs one step
                for(int j=0; j<NUM_LEDS; j++) {
                  if( (!meteorRandomDecay) || (random(10)>5) ) {
                    leds[j].fadeToBlackBy( meteorTrailDecay ); 
                  }
                }
                
                // draw meteor
                for(int j = 0; j < meteorSize; j++) {
                  if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
                    setPixel(i-j, red, green, blue);
                  } 
                }
               
                showStrip();
                delay(SpeedDelay);
              }
            }
            // *** REPLACE TO HERE ***

            If anyone knows of a trick to make LEDs fade in NeoPixel, then I’d love to hear that so we can add this to the list. 

            Happy New Year!

            hans

          • Jan 1, 2018 - 4:56 PM - hans - Author: Comment Link

            Got it to work for NeoPixel as well … so I’ll add it to the article;

            // *** REPLACE FROM HERE ***
            void loop() {
              meteorRain(0xff,0,0,10, 64, false, 30);
            }
            void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
              // red/green/blue = meteor color
              // meteorSize = #LEDs for the meteor (main part, excluding the trail)
              // meteorTrailDecay = fading speed of the trail. 64 = dim by 25% (64/256ths); lower number = longer tail
              // meteorRandomDecay = true of false. False = smooth tail, true = tail that breaks up in pieces
              // SpeedDelay = pause in ms after drawing a cycle - lower number = faster meteor
              
              setAll(0,0,0);
              
              for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
                
                
                // fade brightness all LEDs one step
                for(int j=0; j<NUM_LEDS; j++) {
                  if( (!meteorRandomDecay) || (random(10)>5) ) {
                    fadeToBlack(j, meteorTrailDecay );        
                  }
                }
                
                // draw meteor
                for(int j = 0; j < meteorSize; j++) {
                  if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
                    setPixel(i-j, red, green, blue);
                  } 
                }
               
                showStrip();
                delay(SpeedDelay);
              }
            }
            void fadeToBlack(int ledNo, byte fadeValue) {
             #ifdef ADAFRUIT_NEOPIXEL_H 
                // NeoPixel
                uint32_t oldColor;
                uint8_t r, g, b;
                int value;
                
                oldColor = strip.getPixelColor(ledNo);
                r = (oldColor & 0x00ff0000UL) >> 16;
                g = (oldColor & 0x0000ff00UL) >> 8;
                b = (oldColor & 0x000000ffUL);
                r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
                g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
                b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
                
                strip.setPixelColor(ledNo, r,g,b);
             #endif
             #ifndef ADAFRUIT_NEOPIXEL_H
               // FastLED
               leds[ledNo].fadeToBlackBy( fadeValue );
             #endif  
            }
            // *** REPLACE TO HERE ***

            hans

        • Dec 31, 2017 - 3:15 PM - hans - Author: Comment Link

          Thanks to you Systembolaget!

          Very clean and compact – I like it. I’ll have to test it and see if we can squeeze it in this article as well! 

          Reply

          hans

          • Jan 1, 2018 - 12:57 PM - hans - Author: Comment Link

            Looks really good! Just had a chance to test it. 

            Unfortunately, it would not fit in the “generic” approach of this article, but for those who are looking for this effect: highly recommend trying this one! 

            Happy New Year!

            hans

        • Dec 31, 2017 - 3:15 PM - hans - Author: Comment Link

          Happy New Year to you guys! 

          Reply

          hans

          • Jan 1, 2018 - 10:05 AM - Henrik Lauridsen Comment Link

            Thank you and a happy New Year to you.

            Henrik Lauridsen

  • Dec 25, 2017 - 9:52 AM - Henrik Lauridsen Comment Link

    Hi again,

    I forgot to wish you a merry Christmas and a happy new year

    Reply

    Henrik Lauridsen

  • Jan 1, 2018 - 7:26 AM - Lephilelec Comment Link

    Thanks a lot.

    Really great job !

    See you !

    Reply

    Lephilelec

    • Jan 1, 2018 - 1:01 PM - hans - Author: Comment Link

      Thanks Lephilelec for taking the time to post a Thank-You note! 
      It’s very much appreciated!

      Happy New Year! 

      Reply

      hans

  • Jan 1, 2018 - 9:32 PM - hans - Author: Comment Link

    UPDATE:

    Added a new Effect (thanks Hendrik for pointing me to a cool new effect): Meteor Rain.

    Reply

    hans

    • Jan 28, 2018 - 1:11 PM - arav kumar Comment Link

      HI THERE 

      I want to integrate the meteor rain effect with a ultrasonic sensor .Could you point me in the direction of how exactly to go  about it.

      p.s- I am a newbie at arduino :)

      Reply

      arav kumar

      • Feb 16, 2018 - 10:43 AM - hans - Author: Comment Link

        Hi Arav,

        I have yet to play with an ultrasonic sensor. Not sure if it passes a value or an on/off state.

        Either way, you could setup a loop that checks the sensor. Once the sensor “triggers”, call the meteor effect?

        Reply

        hans

  • Jan 7, 2018 - 3:39 PM - hans - Author: Comment Link

    UPDATE:

    Finally found the time to combine all sketches into one single sketch.
    I’ve created it such a way that you can toggle effect (fast!) with a single button.

    See: Arduino – All LEDStrip effects in one (NeoPixel and FastLED)

    Reply

    hans

  • Jan 14, 2018 - 6:01 PM - Gary Kester - Author: Comment Link

    Hi Hans. I am incredibly grateful for the code and help you’ve added with this post. So very much appreciated. Is there any way to learn the language you’ve used to program these sketches?

    Reply

    Gary Kester

    • Jan 21, 2018 - 1:48 PM - hans - Author: Comment Link

      Thanks Gary!

      I very much appreciate your post! 

      To get started, at some point I wrote a course for my nephews. Maybe this is a good starting point to get familiar with the language.

      Here is the link of the overview page: Arduino Programming for Beginners.

      Don’t be afraid to ask if you have questions … we are all beginners at some point, and I’m 100% sure there are better programmers than me out there that can teach me a few things as well. 

      Reply

      hans

      • Jan 22, 2018 - 4:08 PM - Gary Kester - Author: Comment Link

        We can always do what we do better ;). I’m learning from the bottom up and your tutorial is gold for that. I’m also trying to implement the lighting effects into some of my projects at the same time. e.g. https://youtu.be/R-_Mn9t1OoE

        Have you ever done a sketch that results in 2 different effects to two different sets of neopixels (of different lengths) at the same time?

        I’d like to have the core pulse randomly separate to the circle that I want a superfast spinning effect on.

        Reply

        Gary Kester

        • Jan 25, 2018 - 12:25 PM - hans - Author: Comment Link

          Hi Gary!

          That’s a cool project, which initially (since I forgot to read the “Iron man” text) made me think of a LED ring around a speaker responding to music. Anyhoo – both fun projects! 

          I have not played with multiple strips yet – I’ve always used math to set the LEDs so it looks like 2 strands. FastLED however does support multiple strands, but I can imagine it to be challenging to have 2 or more effects to run in parallel. I’m thinking about timing issues and such.

          I guess I would start using 2 Arduino’s for that – to get max speed as well.

          Then again, if you’d make one procedure handling the spinning – just 1 step, and another one doing just one step of the other effect, and then call them in a certain sequence in loop(); might work.

          Reply

          hans

  • Jan 25, 2018 - 7:22 AM - Henrik Lauridsen Comment Link

    Hi Hans,

    I have a question regarding powering more LED strips.

    I need to power 300 WS2812b LEDs or more, but my PSU can’t handle that much (300 x 60 mA)

    Can I do the following?

    5 LED strips and 5 PSU’s

    Every PSU with common ground including Arduino ground.

    Every strip + connected to VCC on its own PSU

    All strips data pin connected to Arduino data pin 6

    Thank you.

    Henrik 

    Reply

    Henrik Lauridsen

    • Jan 25, 2018 - 12:42 PM - hans - Author: Comment Link

      Hi Hendrik,

      in my practical experience, 300 x 20mA would work or is at least worth a test. This works since not all LEDs are on and at max brightness all the time for a long period of time. Which would suggest a 6A power supply could pull this off.

      If you’d like to use individual PSU’s, then your approach looks good; common GND, Vcc for each strip.

      However if all strips have a common data pin 6, then they most likely all will display the exact same effect. Not sure if that’s what you had in mind.

      If this is NOT what you had in mind then connect the Din of the first strip to Pin 6 of the Arduino. At the end of the first strip you’ll find a Dout pin (follow the arrows) which can be connected to Din of the second strip, and so on, daisy chaining the strips. Power still can still be done per individual LED strip.

      Reply

      hans

      • Jan 26, 2018 - 9:52 AM - Henrik Lauridsen Comment Link

        Hi Hans,

        Thank you for your reply.

        If this is NOT what you had in mind then connect the Din of the first strip to Pin 6 of the Arduino. At the end of the first strip you’ll find a Dout pin (follow the arrows) which can be connected to Din of the second strip, and so on, daisy chaining the strips. Power still can still be done per individual LED strip.

        This was what I meant, but formulated it wrong.

        Thank you again,

        Henrik

        Reply

        Henrik Lauridsen

  • Jan 27, 2018 - 1:28 AM - Gary Kester - Author: Comment Link

    Hi Guys,

    Just adding my contribution. The enclosed sketch is based on the Hero Powerplant sketch done my Tony Sherwood for Adafruit Industries.

    I modified it to allow for 2 sets of Neopixels (1 for the circle – RGBW and another for the core RGB) with different colors running off different pins.

    Video of the effect on Youtube https://www.youtube.com/embed/QStYTdPPeQ4

    //fades all pixels subtly

    //code by Tony Sherwood for Adafruit Industries

    //modified by Gary Kester for Make It Real (Australia)

     

    #include <Adafruit_NeoPixel.h>

     

    #define PIN1 1

    #define PIN2 2

     

    // Parameter 1 = number of pixels in circle

    // Parameter 2 = pin number (most are valid)

    // Parameter 3 = pixel type flags, add together as needed:

    // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)

    // NEO_KHZ400 400 KHz (classic ‘v1’ (not v2) FLORA pixels, WS2811 drivers)

    // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)

    // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

    Adafruit_NeoPixel circle = Adafruit_NeoPixel(10, PIN1, NEO_GRBW + NEO_KHZ800);

    Adafruit_NeoPixel core = Adafruit_NeoPixel(6, PIN2, NEO_GRB + NEO_KHZ800);

     

    int alpha; // Current value of the pixels

    int dir = 1; // Direction of the pixels… 1 = getting brighter, 0 = getting dimmer

    int flip; // Randomly flip the direction every once in a while

    int minAlpha = 25; // Min value of brightness

    int maxAlpha = 100; // Max value of brightness

    int alphaDelta = 5; // Delta of brightness between times through the loop

     

    void setup() {

      circle.begin();

      core.begin();

      circle.show(); // Initialize all pixels to ‘off’

      core.show(); // Initialize all pixels to ‘off’

    }

     

    void loop() {

      flip = random(32);

      if(flip > 20) {

        dir = 1 – dir;

      }

      // Some example procedures showing how to display to the pixels:

      if (dir == 1) {

        alpha += alphaDelta;

      }

      if (dir == 0) {

        alpha -= alphaDelta;

      }

      if (alpha < minAlpha) {

        alpha = minAlpha;

        dir = 1;

      }

      if (alpha > maxAlpha) {

        alpha = maxAlpha;

        dir = 0;

      }

      // Change the line below to alter the color of the lights

      // The numbers represent the Red, Green, and Blue values

      // of the lights, as a value between 0(off) and 1(max brightness)

      //

      // EX:

      colorWipe(circle.Color(alpha, 0, alpha/2)); // Pink

      // colorWipe(circle.Color(0, 0, alpha)); // Blue

      colorWipe2(core.Color(alpha, alpha, alpha)); // Blue

    }

     

    // Fill the dots one after the other with a color

    void colorWipe(uint32_t c) {

      for(uint16_t i=0; i<circle.numPixels(); i++) {

          circle.setPixelColor(i, c);

          circle.show();

          ;

      }

    }

    // Fill the dots one after the other with a color

    void colorWipe2(uint32_t c) {

      for(uint16_t i=0; i<core.numPixels(); i++) {

          core.setPixelColor(i, c);

          core.show();

          ;

      }

    }

    Reply

    Gary Kester

  • Feb 7, 2018 - 6:06 AM - Umberto Giacobbi Comment Link

    Thank you for this fast and cool library!

    Reply

    Umberto Giacobbi

    • Feb 16, 2018 - 11:00 AM - hans - Author: Comment Link

      Hi Umberto!

      Thanks you very much for the compliment! Glad you’re having fun with it as well! 

      Reply

      hans

  • Feb 8, 2018 - 5:20 PM - Sharon Noordermeer Comment Link

    Hello! You have a great website, very fascinating stuff on here!  I am an art student looking to do a sculpture project involving light, and I am stuck because I am using Adadfruit’s drum sound sensor code. Of course, all it is is a sound reactive digital 30 Neopixel light using GEMMA MO and Electret Microphone amplifier. I am using varying pixels because they will be wrapped around trees like belts, and whenever someone speaks, it should light up. Problem is I do not want simple bars and rainbow lighting as the code is given, I want something like your last demo the Meteor light or something simpler like a trail of light across the strip. Could you help me customize this code? The project is due next Wednesday (Valentine’s day).

    you can read their code from this link

    https://learn.adafruit.com/gemma-powered-neopixel-led-sound-reactive-drums/circuit-diagram

    or

    Here is the code:

    * LED “Color Organ” for Adafruit Trinket and NeoPixel LEDs.

    Hardware requirements:
    – Adafruit Trinket or Gemma mini microcontroller (ATTiny85).
    – Adafruit Electret Microphone Amplifier (ID: 1063)
    – Several Neopixels, you can mix and match
    o Adafruit Flora RGB Smart Pixels (ID: 1260)
    o Adafruit NeoPixel Digital LED strip (ID: 1138)
    o Adafruit Neopixel Ring (ID: 1463)

    Software requirements:
    – Adafruit NeoPixel library

    Connections:
    – 5 V to mic amp +
    – GND to mic amp –
    – Analog pinto microphone output (configurable below)
    – Digital pin to LED data input (configurable below)

    Written by Adafruit Industries. Distributed under the BSD license.
    This paragraph must be included in any redistribution.
    */
    #include <Adafruit_NeoPixel.h>

    #define N_PIXELS 27 // Number of pixels you are using
    #define MIC_PIN A1 // Microphone is attached to Trinket GPIO #2/Gemma D2 (A1)
    #define LED_PIN 0 // NeoPixel LED strand is connected to GPIO #0 / D0
    #define DC_OFFSET 0 // DC offset in mic signal – if unusure, leave 0
    #define NOISE 100 // Noise/hum/interference in mic signal
    #define SAMPLES 60 // Length of buffer for dynamic level adjustment
    #define TOP (N_PIXELS +1) // Allow dot to go slightly off scale
    // Comment out the next line if you do not want brightness control or have a Gemma
    //#define POT_PIN 3 // if defined, a potentiometer is on GPIO #3 (A3, Trinket only)

    byte
    peak = 0, // Used for falling dot
    dotCount = 0, // Frame counter for delaying dot-falling speed
    volCount = 0; // Frame counter for storing past volume data

    int
    vol[SAMPLES], // Collection of prior volume samples
    lvl = 10, // Current “dampened” audio level
    minLvlAvg = 0, // For dynamic adjustment of graph low & high
    maxLvlAvg = 512;

    Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);

    void setup() {
    //memset(vol, 0, sizeof(vol));
    memset(vol,0,sizeof(int)*SAMPLES);//Thanks Neil!
    strip.begin();
    }
    void loop() {
    uint8_t i;
    uint16_t minLvl, maxLvl;
    int n, height;
    n = analogRead(MIC_PIN); // Raw reading from mic
    n = abs(n – 512 – DC_OFFSET); // Center on zero
    n = (n <= NOISE) ? 0 : (n – NOISE); // Remove noise/hum
    lvl = ((lvl * 7) + n) >> 3; // “Dampened” reading (else looks twitchy)

    // Calculate bar height based on dynamic min/max levels (fixed point):
    height = TOP * (lvl – minLvlAvg) / (long)(maxLvlAvg – minLvlAvg);

    if(height < 0L) height = 0; // Clip output
    else if(height > TOP) height = TOP;
    if(height > peak) peak = height; // Keep ‘peak’ dot at top

    // if POT_PIN is defined, we have a potentiometer on GPIO #3 on a Trinket
    // (Gemma doesn’t have this pin)
    uint8_t bright = 255;
    #ifdef POT_PIN
    bright = analogRead(POT_PIN); // Read pin (0-255) (adjust potentiometer
    // to give 0 to Vcc volts
    #endif
    strip.setBrightness(bright); // Set LED brightness (if POT_PIN at top
    // define commented out, will be full)
    // Color pixels based on rainbow gradient
    for(i=0; i<N_PIXELS; i++) {
    if(i >= height)
    strip.setPixelColor(i, 0, 0, 0);
    else
    strip.setPixelColor(i,Wheel(map(i,0,strip.numPixels()-1,30,150)));
    }

    strip.show(); // Update strip

    vol[volCount] = n; // Save sample for dynamic leveling
    if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter

    // Get volume range of prior frames
    minLvl = maxLvl = vol[0];
    for(i=1; i<SAMPLES; i++) {
    if(vol[i] < minLvl) minLvl = vol[i];
    else if(vol[i] > maxLvl) maxLvl = vol[i];
    }
    // minLvl and maxLvl indicate the volume range over prior frames, used
    // for vertically scaling the output graph (so it looks interesting
    // regardless of volume level). If they’re too close together though
    // (e.g. at very low volume levels) the graph becomes super coarse
    // and ‘jumpy’…so keep some minimum distance between them (this
    // also lets the graph go to zero when no sound is playing):
    if((maxLvl – minLvl) < TOP) maxLvl = minLvl + TOP;
    minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
    maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
    }

    // Input a value 0 to 255 to get a color value.
    // The colors are a transition r – g – b – back to r.
    uint32_t Wheel(byte WheelPos) {
    if(WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 – WheelPos * 3, 0);
    } else if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 – WheelPos * 3, 0, WheelPos * 3);
    } else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 – WheelPos * 3);
    }
    }

    Reply

    Sharon Noordermeer

  • Feb 15, 2018 - 11:13 AM - Dan Rutter Comment Link

    Thank you so much for putting this lot together an incredible resource. I am trying to work out how to run three of these effects from three different pins. I am building a brain storming hat for a party that has a Cloud which i would like to have the Multi colour sparkle. Then two Tubes with LEDs in that will run the Meteor sequence down to two 16 pixel rings that will Cycle up in colour showing the “charge” in the helmet. I was hoping to add sound and some Other lights in the cloud to strobe to signify Lightning ( but time is not on my side)

    . Any help or directions to Previous topics that might help would be greatly appreciated thank you all very much. 

    Reply

    Dan Rutter

    • Feb 16, 2018 - 11:25 AM - hans - Author: Comment Link

      Hi Dan,

      I’d recommend using 3 Arduino’s instead of trying to run 3 different effects on one Arduino.
      The code would become quite challenging.

      Since you’d want to use something small; check out the Arduino Nano, and if you’re more experienced the ESP8266.

      Reply

      hans

  • Mar 2, 2018 - 1:19 PM - Tim Comment Link

    I’m learning about arduino for pixels in trying to build a home theater marquee. I’ve used your code example and got a basic marquee chase working but I’m confused one a couple things. I’m not understanding how to set the speed delay. My brain just isn’t processing the code for it.

    I’m also trying to figure out how to use multiple pixels as one, like 2 or 3 pixels count as 1 unit with the units chasing.

    Lastly, I’ve seen a video on YouTube with someone doing a similar project and he was able to run 4 or 5 different versions of a chase off 1 board, all switched with a simple button press. Any idea how that might work?

    Thanks for any advice you can offer!

    Reply

    Tim

    • Mar 3, 2018 - 5:41 AM - hans - Author: Comment Link

      Hi Tim,

      apologies for the late response … (I’m in the middle of a move from the US to Europe)

      The speed delay basically is the time “consumed” between each step.
      See it as: LED1 on, wait x milliseconds, LED1 off, LED2 on, wait x milliseconds, LED2 off, LED3 on, wait x milliseconds, etc.
      The higher the number, the slower the chase will be.

      I don’t have my equipment near me (it’s in a big container somewhere on the ocean hahah), but I’d look in this part of the code:

      void theaterChaseRainbow(int SpeedDelay) {
        byte *c;
        
        for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
          for (int q=0; q < 3; q++) { // <--- look in this for loop
              for (int i=0; i < NUM_LEDS; i=i+3) {
                c = Wheel( (i+j) % 255);
                setPixel(i+q, *c, *(c+1), *(c+2)); //turn every third pixel on
              }
              showStrip();
             
              delay(SpeedDelay);
             
              for (int i=0; i < NUM_LEDS; i=i+3) {
                setPixel(i+q, 0,0,0); //turn every third pixel off
              }
          }
        }
      }

      I’ve marked the 5th line, in this for-loop you will have to do some coding to make a single LED become “bigger”.
      While thinking about this, there maybe a more elegant way to do this … I’d probably make a virtual LED array, populate it as done in this code (so instead of “setPixel”). Then call my own procedure that “translates” the virtual LED to a set of 3 LEDs. This does require some extra work of course.

      I have yet to experiment with multiple strands on one board. Libraries like FastLED so support this though, but your loop will become a little more complex since you want to effects to work independently. If they do not need to run independently and you’re OK with all strips doing exactly the same thing, then things become more simple: you can connect all LED strips in parallel (so the Din wire of all strips tied together and connected to the same pin on the Arduino).

      Reply

      hans

      • Mar 3, 2018 - 12:01 PM - Tim Comment Link

        I appreciate the response.

        I may not have been clear in my first post. I understand what a delay is, just not how to read it within this code. The language is very Greek to me. Not trying to become an expert either but tinkering a bit for a couple projects.

        I think what I’m trying to achieve is one block of code with 3-5 different chase-style patterns/colors that can easily be changed with the press of an auxiliary button. I do have some chasing EL wire that I need to control as well and if 1 arduino nano can handle both that would be perfect but if I have to use a second controller it’s not a huge deal.

        I will tinker some more and ask if I have anymore questions.

        Thank you and safe travels!

        Reply

        Tim

        • Mar 7, 2018 - 2:57 AM - hans - Author: Comment Link

          Hi Tim!

          Thanks for the safe travels wish! I’ve made it to Europe – now wait another month before my belongings get here. Yikes!

          Which of the two theatre chase examples were you looking at?
          I don’t mind helping to “un-Greek” the code 

          Reply

          hans

          • Mar 8, 2018 - 4:21 AM - Spike Comment Link

            Wow! You’re moving to Europe eh Hans … UK by any chance?

            Spike

          • Mar 11, 2018 - 3:14 AM - hans - Author: Comment Link

            Yeah … I’m moving to The Netherlands … sorry, not the UK. I’d stop by for a beer otherwise 

            hans

          • Mar 22, 2019 - 2:04 AM - Tim Comment Link

            Hello Hans,

            Just digging into the project again after having to shelf it for a bit.

            I’ve found your posting on combining multiple effects into one string that can then be changed with a SPST switch. Got that working but now Im tweeking the theater chase modes. I’m doing different light timings but still not sure how to adjust the speed delay.

            Is it also possible to reverse the direction?

            lastly, and maybe this requires all new coding but can the chase be set so all lights are on at a “dim” level and the chase lights are just turned up brighter”.

            Any help is appreciated. I unfortunately don’t have the time to invest in learning as much code as possible right now but would like to put some cool lights to good use!

            Cheers!

            Tim

          • Mar 22, 2019 - 6:39 AM - hans - Author: Comment Link

            Hi Tim,

            you’ve got quite a few questions there 

            To reverse the TheatreChase, you’ll have to reverse the for-loop, for example, like so:

            void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
              for (int j=0; j<10; j++) { //do 10 cycles of chasing
                for (int q=0; q < 3; q++) {
                  for (int i=0; i < NUM_LEDS; i=i+3) {
                    setPixel(NUM_LEDS-i+q, red, green, blue); //turn every third pixel on
                  }
                  showStrip();
                 
                  delay(SpeedDelay);
                 
                  for (int i=0; i < NUM_LEDS; i=i+3) {
                    setPixel(NUM_LEDS-i+q, 0,0,0); //turn every third pixel off
                  }
                }
              }
            }

            (I have not tested this, but it seemed the easiest fix)

            To have the strand have dimmed lights instead of OFF, you could do this:

            #define ChaseBaseBrigthness 10
            ...
            void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
              for (int j=0; j<10; j++) { //do 10 cycles of chasing
                for (int q=0; q < 3; q++) {
                  for (int i=0; i < NUM_LEDS; i=i+3) {
                    setPixel(NUM_LEDS-i+q, red, green, blue); //turn every third pixel on
                  }
                  showStrip();
                 
                  delay(SpeedDelay);
                 
                  for (int i=0; i < NUM_LEDS; i=i+3) { // 2nd loop!!
                    setPixel(NUM_LEDS-i+q, ChaseBaseBrigthness,ChaseBaseBrigthness,ChaseBaseBrigthness); //turn every third pixel off
                  }
                }
              }
            }

            I have not tested this one either (play with the value of ChaseBaseBrightness, and you may have to so a “setAll(ChaseBaseBrigthness,ChaseBaseBrigthness,ChaseBaseBrigthness)” before calling the function.

            In the second for-loop you could define a color instead as well (instead of 2xChaseBaseBrigthness). If the dimmed color has to match the red,green,blue, then you may have to do a calculation to determine the dimmer value for red, green and blue.

            Hope this is what you’re looking for.

            hans

          • May 16, 2019 - 10:26 AM - Tim Comment Link

            Hello again Hans,

            About ready to put your awesome code into action and your below help got the “always” on function for the theater chase working.

            However I’ve not been able to figure out how to possibly reverse the direction of the theater chase. I compared the code you posted to what I had but didn’t see any differences that changed the actions.

            I’m actually working with your full sketch of all functions and picking out the ones that work best for my set-up. I have the button working to change functions but I’m curious if a second button can be added to go backwards through the list?

            And I am also hoping to be able to reverse the direction of the RunningLights as until my project is fully built I’m not sure what will look best and currently the Theater Chase runs one direction and the Running Lights go the other! 

            Thanks for any help as always!

            Cheers!

            Tim

        • May 19, 2019 - 11:13 AM - hans - Author: Comment Link

          Hi Tim,

          Sorry for the late reply; it took me a little bit to catch up again 

          Basically what you’d want to do, is have the for-loop count in the opposite direction.
          Either by reversing the loop, or by calculating the LED pixel at ShowPixel().
          Maybe I’m not awake enough yet … let me try again – I do not have any hardware near by to test.

          void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
            for (int j=0; j<10; j++) { //do 10 cycles of chasing
              for (int q=2; q >= 0; q--) { // I think this may give the reverse look
                for (int i=0; i < NUM_LEDS; i=i+3) {
                  setPixel(i+q, red, green, blue); //turn every third pixel on
                }
                showStrip();
               
                delay(SpeedDelay);
               
                for (int i=0; i < NUM_LEDS; i=i+3) {
                  setPixel(i+q, 0,0,0); //turn every third pixel off
                }
              }
            }
          }

          For RunningLights you could try this;

          void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
            int Position=0;
            
            for(int j=(NUM_LEDS*2)-1; j>=0; j--) // this may work
            {
                Position++; // = 0; //Position + Rate;
                for(int i=NUM_LEDS-1; i>=0; i--) { // and here
                  setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                             ((sin(i+Position) * 127 + 128)/255)*green,
                             ((sin(i+Position) * 127 + 128)/255)*blue);
                }
                
                showStrip();
                delay(WaveDelay);
            }
          }

          Apologies if this doesn’t work out right away – after doing so much work on ApplePi-Baker (one of my projects) I’m experiencing a little brain-fog 

          Reply

          hans

          • May 19, 2019 - 3:38 PM - Tim Comment Link

            Hello Hans,

            As always, thanks for taking the time to look into this. I will give your code examples a shot.

            I was hoping to be able to program the Arduino with a few functions, firstly controlling the LEDs but secondly to control an IR LED performing a few functions of a TV remote. Basically upon powering on, having the Arduino send a Power On signal to the TV and possibly upon main losing power having enough charge built up in a capacitor to fire off a Power Off signal to the TV. I wanted to integrate a 3×4 Matrix keypad in to be able to select the lighting sequences and use a few other commands for the TV like volume and input. I’ve tried asking for some help elsewhere but it seems there’s a lot of expectation for people to learn full programming languages when they only want to figure out a few small things so I very much appreciate that you took the time to write your code and tutorials and continue to provide support to us who keep asking for help.

            Keep being awesome!

            Tim

          • May 20, 2019 - 5:00 AM - hans