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 consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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)
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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:
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 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 NOTconnect to a PC!
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 twocharacters is for GREEN and
the last 2characters 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);
Ad Blocking Detected
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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.
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.).
// *** REPLACE FROM HERE *** void loop(){ // ---> here we call the effect function <--- } // ---> here we define the effect function <--- // *** REPLACE TO HERE ***
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.
#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 ***
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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.
void RGBLoop(){ for(int j =0; j <3; j++){ // Fade IN for(int k =0; k <256; k++){ switch(j){ case0: setAll(k,0,0);break; case1: setAll(0,k,0);break; case2: setAll(0,0,k);break; }
showStrip();
delay(3); } // Fade OUT for(int k =255; k >=0; k--){ switch(j){ case0: setAll(k,0,0);break; case1: setAll(0,k,0);break; case2: 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 }
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(); } }
Ad Blocking Detected
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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!
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:
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.
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); }
Ad Blocking Detected
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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.
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
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.
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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).
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).
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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:
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).
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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 }
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).
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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.
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.
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 } } } }
Ad Blocking Detected
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
LEDStrip Effect – Theatre Chase Rainbow
Another one from NeoPixel, which combines Rainbow and TheatreChase.
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 } } } }
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.
// 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); }elseif( t192 >0x40){// middle
setPixel(Pixel,255, heatramp,0); }else{// coolest
setPixel(Pixel, heatramp,0,0); } }
Ad Blocking Detected
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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.
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.
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:
for(int i =0; i < BallCount ; i++){
setPixel(Position[i],colors[i][0],colors[i][1],colors[i][2]); }
showStrip();
setAll(0,0,0); } }
Ad Blocking Detected
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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.
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.
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
Please consider disabling your ad blocker for our website. We rely on these ads to be able to run our website. You can of course support us in other ways (see Support Us on the left).
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.
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).
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 …
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.
[…] 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 […]
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!
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.
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' }
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
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.
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?
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).
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.
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.
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?
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.
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.
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.
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…
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.
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 …
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?
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.
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.
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.
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!
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)
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.
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.
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.
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 …
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 …
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?
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 …
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?
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.
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?
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.
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.
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.
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
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?
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!
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.
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 ***
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
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.
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
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.
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
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.
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.
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?
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.
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?
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!
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.
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 :(
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:
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
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!!
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);
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.
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.
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.
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 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.
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.
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
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!
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.
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
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 …
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.
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)
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 );
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 …
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)
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 …
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.
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.
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
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.
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.
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.
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.
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)
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.
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.
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.
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…
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
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
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.”
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.
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.
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.
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.
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.
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).
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.
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).
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..
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.
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 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.
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.
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.
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?
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).
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.
// *** 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.
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.
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.
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?
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.
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.
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?
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:
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(); }
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 ***
#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); }
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(); }
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.
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.
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!
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);
}
}
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).
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?
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.
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.
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!!
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 …
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).
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!
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.
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.
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.
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?
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?
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.
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
It is best to start a forum topic in our Arduino forum for this. I monitor this daily, and it would keep off-topic and long source codes away from these comment sections. Do however feel free to post the link to the forum topic here to grab the attention of others.
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
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.
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?
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?
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.
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:
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]
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?
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); } }
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.
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?
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 …
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.
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!
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. :)
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.
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.
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 } } } }
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. )
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.
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.
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.
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(); } }
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?
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 …
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
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.
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.
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
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.
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!
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.
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.
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?
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.
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(); }}
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.
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.
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).
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; }
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 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.
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.
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!
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;
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.
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.
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.
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); } }
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)
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):
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.
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.
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
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
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!
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 …
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.
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();
#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 }
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;
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;
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.
//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; }
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.
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 …
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?
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
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
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,…
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) {
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
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)
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.
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 ); } }
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
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!
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.
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?
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.
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.
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.
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.
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.
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.
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).
* 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)
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;
// 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);
}
}
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.
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?
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:
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).
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.
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!
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.
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!
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
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.
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.
Great tutorial! Thanks so much for sharing the examples and creating the videos!
Michael
Thanks Michael for taking the time to post a “Thank you” note! It’s very much appreciated!
hans
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.
seaworld
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
Evghenii
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 …
hans
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.
Kevin Z
Thank you for sharing your work !
bogdan
You’re welcome Bogdan, and thanks for taking the time to post a “Thank you”
hans
[…] 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 […]
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!
Chuck
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.
hans
Thanks Hans, I appreciate the help! I will start a topic in the Arduino Forum, thank you for pointing me the way! :-)
Chuck
I’ll be looking forward to your post
hans
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:
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.
David
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 …
hans
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?
dp34067
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.
hans
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?
Richard Amador
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).
hans
Hello Hans,
I switched browsers from Firefox to Google Chrome and all seems well, but that may be a coincidence!
dp34067
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.
hans
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.
Adnan
Hi Adan,
There are no stupid question ….
Setting the entire strip in one color can be done (in this framework) with:
So for example for setting all LEDs to blue:
hans
thank you so much!
askfriends
You’re welcome.
p.s. I also posted some code in your forum topic.
hans
Just wanna thank you for this great tutorial with flexible codes and videos! Awesome!
Hadj
Thank you for taking the time to post a “Thank you” Hadj!
It’s much appreciated …
hans
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?
matt.h
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.
hans
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.
Nils-Johnny Friis
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.
hans
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!
Greg Wren
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! )
hans
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.
mikewolf
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 …
hans
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?
mikewolf
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.
flow in
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.
mikewolf
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!
hans
Once I get the NewKitt routine to change colors everytime the eyes hit the sides or each other, my life will be complete
mikewolf
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):
Obviously, this can be done nicer, and I don’t know if only 2 colors would be OK for your purposes.
hans
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
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
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)
imdr5534
Hi Imdr5534 ….
I had to move the lengthy code to the forum. Apologies for that.
I’ll post an answer there.
hans
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!
KTTJ
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.
hans
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++);
abarrelofmonkeys
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 …
hans
For those interested in effects for Christmas, look at Spike’s project in this forum post.
hans
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
spike
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 …
hans
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!
spike
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
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?
Anthony
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.
hans
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!!!!!
Anthony
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.
hans
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
Hi Anthony,
Could you post the exact steps and error message?
hans
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.
Anthony
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.
hans
p.s. you’ll find the examples in File->Examples->FastLED
hans
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?
Anthony
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
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.
Anthony
Awesome!
Feel free to post links here, or send me pictures (I can place pictures in the comments for you).
hans
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.
hans
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);
}
Anthony
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.
Anthony
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:
hans
Thank You, Thank You, Thank You, Thank You…………. Finally its working just as it should.
Anthony
Awesome! Good to hear that!
hans
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
Steve
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.
hans
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
Steve
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.
hans
I couldnt get it to work (typo)
Steve
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
ap0ll0
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 …
ap0ll0
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.
hans
Interested in cool effects and uses of effects, checkout App0ll0’s work in the forum … it looks awesome!
hans
hi how to do that was to be turned on and off by pressing button
chemix
Awesome guide and resource, many thanks and praise for all of the useful info, demos, and code! Can’t wait to fiddle with these-
Kent Caldwell
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?
tidehunter
Hi TideHunter,
I’d start with playing with the while loop in line 26 (while (true) {), maybe change that to some like this:
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.
hans
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?
jacchavez
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
hans
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?
kylegap
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:
to this:
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;
Hope this helps
hans
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
Jesse
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
hans
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
mikewolf
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:
mikeb1479
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).
Paste this in the Arduino IDE editor.
Now select this section in this code:
and replace it with the function you found with the effect you’d like to use, for example for the FadeInOut effect:
I hope this makes more sense now … please feel free to ask though!
hans
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
mikeb1479
Awesome Mike!
Glad I could help … have fun with the LED strips (I know I do!).
hans
i have been, theyre now being used as xmas lights :D
mikeb1479
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
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
Nice!
hans
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
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!!
xena2000
Hi Xena2000,
sorry for the late reply.
In essence you’d need to change the “for” loops in fire() function. For example (untested):
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).
hans
I created an Android application to control it via Bluetooth:
https://github.com/thiagolr/lightita
Thiago
Hi Thiago,
very nice!!! Thanks for sharing!
hans
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.
Spike
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
Thiago
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
spike
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
Thanks a lot!!!!
have a nice days!!
Aldo
Thanks! You too Aldo!
hans
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:
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.
Andrew
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.
hans
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.
gbonsack
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:
It could be done more elegant of course, but this would probably be an easy start.
hans
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.
gbonsack
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
hans
That’s it. Happy Holiday’s
gbonsack
Merry Christmas and a Happy New Year to you too
hans
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!!!!!!!!
Aldo
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;
This keeps going forever of course. You could modify this to a loop, or a time count.
Hope this helps
hans
thanks a lot!!! bye.. Hans!!!
rompipelotas
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
Claire Tompkins
Hi Claire!
Welcome back …
Maybe this will be helpful;
The function is called as such:
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:
… and change the “void loop() {” to something like this:
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() { … }”.
Just an idea to add more randomness to the whole thing: make the color brightness intensity random as well:
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
hans
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
Claire Tompkins
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 …
hans
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
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
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 —
Peter Bohus
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.
hans
Thanks, it all works now!
Thanks again!:)
Peter Bohus
Awesome!
hans
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
Peter Bohus
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:
Green:
Blue:
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):
I have not tested any of these, but I’m confident this will do the trick …
hans
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
Peter Bohus
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;
I have not been able to test this though … but it might get you started.
You’d call it in the void loop.
Hope this helps …
hans
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
Drax
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.
hans
Made a video showing what is wrong here. I that an LED tape issue, arduino issue or power supply issue ?
Drax
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 …
hans
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.
gbonsack
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.
hans
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.
Guy-Laurent
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)
hans
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
BravoZulu
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
cam
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
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?
hans
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
« 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):
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
Bingo !
With an image (alone) of 86KB.
BravoZulu
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
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
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
I got the comment window this AM??? System re-booted over night??? Flip-A-Coin
gbonsack
Hi Gbonsack …
ehm, you mean your system rebooted? Not sure what you’re referring to
(I need more coffee – that’s for sure )
hans
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.
cam
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.
cam
I actually could open a new topic on the forum. Follow up there.
cam
You have saved me so much time….Tons of love.
Warren Richardson
Hi Warren!
Thanks for taking the time to post a “Thank you” … glad to hear you’ve enjoyed this article!
hans
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.
gbonsack
I just replied with a suggestion the forum.
Others; please feel free to join the conversation with better and/or smarted solutions!
hans
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.
gbonsack
Awesome! Very nice effects! Love the stills as well!
hans
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.
Stan
Hi Stan,
these variables are defined on the fly. For example:
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).
hans
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.
Stan
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).
hans
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..
Stan
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
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
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!
hans
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
candy
Sorry i dont understand what is color wipe
Stan
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
};
gbonsack
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.
hans
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?
candy
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();
}
gbonsack
thank you very much, Gbonsack
candy
i try it that is good result for me. thank you for your time. thank you very much….
candy
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):
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).
hans
thank you Hans
BUt i have another problem to come out.. plz help.
candy
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
Hi Candy,
I do not have my Arduino stuff nearby, but you could try this modified code:
Not sure if the colors will appears as desired …
The code would replace this section:
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.
hans
thank you very much, Hans.
candy
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
Trollo_meo
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
hans
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.
gbonsack
That’s just awesome! I probably should dig into this topic as well – looks really great!
Thanks for sharing!
hans
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?
Ben Linsenmeyer
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.
hans
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.
gbonsack
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?
Marc Johnston
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:
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:
hans
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:
Marc Johnston
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):
For example with:
hans
And also, here is a working sketch from Adafruit:
Marc Johnston
Hi Marc,
the only exceptional things I see in this working code is:
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
hans
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
Marc Johnston
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
Spike
Awesome Spike!
What brand/model 3D printer do you use?
hans
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
Hi Marc!
Thanks for the video – that looks awesome!
The fire effect would indeed be very cool for this purpose!
hans
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
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
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
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
You’re very welcome mate. Glad they are working well for you.
Spike
I just wanted to thank you for the code examples!
Bret
Thanks Bret for taking the time and effort to post a Thank-You — it’s much appreciated!
hans
Thank you for sharing the code and beautiful videos with clear details!!!
Prasanna K
Hi Prasanna!
Thank you very much for the compliment and for taking the time to post a “Thank you” – it’s very much appreciated!
hans
Trying to figure out how to reverse the direction of the running lights code. Any help is appreciated!
Steve Doll
If you like to have the LEDs run into the opposite direction, just:
Is this what you’re looking for?
hans
Doesnt seem to change the direction
Steve Doll
Doh, I modified the wrong for-loop … I should drink more coffee before replying hahah …
I’m sorry – I do not have my Arduino and LEDs anywhere near me, so I cannot test …
hans
Appreciate the help, unfortunately that makes the LEDs not work at all
Steve Doll
I guess I’ll have to find an Arduino + LED strip to do some testing …
hans
One last tweak needed to get the lights to run in reverse, setting the Position to the end and decreasing it:
Gizmo Props
Thanks for chiming in Gizmo Props! Awesome!
Hans
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!!
Sebastian Krupnik
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).
hans
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
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
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.
chris
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.
hans
Sure anything that would help me would be great also this is helping me learn to code
Chris
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!!
Moreno Antunes
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 …
hans
candy
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???
Jeffrey T Pruitt
Hi Jeffrey,
thanks for the compliment!
As for the heartbeat code you found, this can be modified to:
This code should replace the following lines in the base code of this article:
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).
hans
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!
Jeffrey T Pruitt
You’re most welcome …
Did it work as expected?
hans
[…] Arduino – LEDStrip effects for NeoPixel and FastLED […]
hi there is anyone can tell me that these codes will work on RGB led strip as well thx
lucky kang
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?
hans
is these code on these RGB strips thx
http://www.ebay.com/itm/2x-5M-SMD-Remote-RGB-LED-Strip-light-5050Waterproof-300-44-Key-12V-Supply-Power-/272375557890?hash=item3f6ad92f02:g:ZbMAAOSwmfhX2LgF
lucky kang
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.
hans
can u recommend and good RGB led strips thx
lucky kang
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.
hans
hi i order ws2811 from ebay and the all three colour work except white why is that anyone help thx
jony
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?
hans
ok
lucky kang
so can you tell me how can i do that please thx
jony
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).
hans
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?
prof
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.
hans
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
lucky kang
Hi Lucky,
It is best to start a forum topic in our Arduino forum for this. I monitor this daily, and it would keep off-topic and long source codes away from these comment sections.
Do however feel free to post the link to the forum topic here to grab the attention of others.
hans
anyone knows how to add pir sensor click the link for the topic forum thx https://www.tweaking4all.com/forums/topic/how-to-add-two-pir-sensor-stair-project/
luckykang
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
John
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?
Wrybread
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.
hans
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
Daniel
Hi Daniel!
Welcome!
I’m not sure what you mean? Are you thinking of running 8 strips in parallel?
hans
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!
Dan
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
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
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):
and
If you want to add more colors, you can add a line like this for each color you’d want:
If you want a ton of colors for the colour wipe, then consider using for-loops (see also the little course).
For example:
This example would go through all colors (16 million), so you might want to narrow that down haha.
Hope this is helpful.
hans
Thanks Hans, this is great! I’ll get stuck into all of that, plenty of material to get me started!
Thanks again
Dan
Cool! Well, feel free to ask if you run into issue or have questions …
hans
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
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):
and replace that line with:
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
[…] Tweaking4All’s also really nice Fire neopixel sketch. Same comments as with John’s work. THANK YOU. […]
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.
Tony
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
hans
Thank you for the reply. I actually modified the code on my own in a similar manner.
Tony
[…] https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ […]
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.
Dhiraj Kumar
Ha!
JaquesHaas
I would like to repeat the Dhiraj Kumar’s question!
Daniel Fernandes
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?
hans
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
John
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 …
hans
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.
Brian
Awesome!
Thanks for the info Brian!
hans
[…] ici est LEDStrip Effect – Snow Sparkle, mais a cette adresse on peux trouver plein d’autres […]
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.
Ian
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!
hans
Thank you very much for this great site and nice examples
Henrik Lauridsen
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!
hans
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. :)
Dai
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.
hans
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.
Dai
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!
hans
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.
Spike
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. )
Dai
It’s all about team work! And LED strips are fun to play with hahah
hans
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?
astro0302
Hi Astro0302!
The modification for that shouldn’t be too hard.
Try something like this:
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.
hans
Hi Hans! Thanks for your fast reply. Works great!
Now my ledstripe has the right WAF.
Andreas
astro0302
Awesome!
hans
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.
Dai
Sorry, posted around the same time as Hans, and his solution is far more elegant than mine.
Dai
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
John
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 …
hans
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.
Dai
Got the sketch working just fine. Now comes the fun of tweaking it!
A question on the lines below:
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
circuitdriver
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.
hans
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
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
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
fred49
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):
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!
hans
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
fred49
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!
hans
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
Wow that looks cool!
I’m not sure about the code you’ve used, but per strand you could change one of these variables;
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.
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
Hi !
Thanks for all
in fact , this is my program i use :
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
What you could do is make the gravity value a random value – not too much different from the original of course:
to
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
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?
Dhiraj Kumar
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.
hans
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(); }}
Eric
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).
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?
hans
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!
eric
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).
hans
Tried adding DelayValue=x and got errors. Mind showing how you would use it and why it causes the speed change. Thanks Hans!!
Code below where I’m calling FadeIn
eric
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:
or
hans
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
eric
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
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!
Systembolaget
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!
hans
Ok, thanks for your input! I bought:
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.
Systembolaget
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.
Systembolaget
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!
hans
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
NORMAL METHOD (using delay)
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.
Dai
Thanks Dia!
Your info is much appreciated – great tip! – and I’m sure users will have benefit from it! Awesome, thanks!
hans
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
Trinitor
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.
Dai
Thanks – I’ve listed this for my ESP8266 future projects as well
hans
Be advised that the fastPixel library has problems with the 8266, but the neo seems fine.
Mike Garber
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
hans
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 :-
And the Serial output I get is :-
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)
Dai
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):
Maybe not exactly the correct programmers way to do this, but worth a test.
hans
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.
Dai
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)?
hans
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
Dai
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 :-
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
Hi Dai!
Great to hear you’re happy with the result and thanks for posting your function!
hans
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!
Systembolaget
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 …
hans
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.
Dai
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.
Systembolaget
Awesome! Thanks Systembolaget for posting this!!
hans
This subtle change allows for hue, saturation and brightness control. Randomised or clamped to a range. Enjoy!
Systembolaget
Nice! You’re having fun with the LED strips, aren’t you? (me too!)
Thanks again for posting your code!
hans
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 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:
Daniel
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.
to (for example – i don’t think this is very elegant):
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;
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.
hans
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().
Daniel
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
I’d write as:
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:
Hope this helps … and Merry Christmas
hans
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 :-)
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
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:
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
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.
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
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
Maike
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.
hans
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!
maike
Hi Maike!
Merry Christmas to you too!
Glad to hear your project worked out … actually sounds like an interesting project!
hans
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
maike
Oh wow! that looks nice! Well done!
I’ll have to look into that some more as well … I like it!
hans
Hi Hans,
Could you show an meteor rain example. Thank you in advance,
Henrik
Henrik Lauridsen
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
hans
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
Henrik Lauridsen
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,…
hans
Hi Hans,
Thank you for your time.
I am looking forward to your solution with excitement.
Henrik Lauridsen
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.
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
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
Hej,
here’s one with a sparkling and adjustable length trail. Colour can be fixed or change, too. Happy Easter!
Systembolaget
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
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:
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
Got it to work for NeoPixel as well … so I’ll add it to the article;
hans
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!
hans
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
Happy New Year to you guys!
hans
Thank you and a happy New Year to you.
Henrik Lauridsen
Hi again,
I forgot to wish you a merry Christmas and a happy new year
Henrik Lauridsen
Thanks a lot.
Really great job !
See you !
Lephilelec
Thanks Lephilelec for taking the time to post a Thank-You note!
It’s very much appreciated!
Happy New Year!
hans
UPDATE:
Added a new Effect (thanks Hendrik for pointing me to a cool new effect): Meteor Rain.
hans
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 :)
arav kumar
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?
hans
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)
hans
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?
Gary Kester
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.
hans
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.
Gary Kester
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.
hans
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
Henrik Lauridsen
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.
hans
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
Henrik Lauridsen
I guess we are talking about the same approach then
hans
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();
;
}
}
Gary Kester
With a link this time https://youtu.be/QStYTdPPeQ4
Gary Kester
Hi Gary,
Thats fantastic, thanks for sharing your work.
I’m planning to build some more Christmas lights and I’ve been pondering on a way to use more than one strip/string on individual pins.
This will help a lot.
Spike
Thanks Gary! Awesome!
hans
Thank you for this fast and cool library!
Umberto Giacobbi
Hi Umberto!
Thanks you very much for the compliment! Glad you’re having fun with it as well!
hans
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);
}
}
Sharon Noordermeer
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.
Dan Rutter
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.
hans
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!
Tim
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:
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).
hans
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!
Tim
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
hans
Wow! You’re moving to Europe eh Hans … UK by any chance?
Spike
Yeah … I’m moving to The Netherlands … sorry, not the UK. I’d stop by for a beer otherwise
hans
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
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:
(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:
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
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
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.
For RunningLights you could try this;
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
hans
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