# LED Effects - Cross shaped – – Arduino – Forum

Page 1 of 1

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!

LED Effects - Cross...

Share:
Clear all

# LED Effects - Cross shaped

6 Posts
2 Users
0 Likes
1,487 Views
(@hans)
Joined: 10 years ago
Posts: 2554
Topic starter

Based on this comment/request under the LED Effects article by Stanislav, looking for this effect:

Topic Tags
(@hans)
Joined: 10 years ago
Posts: 2554
Topic starter

First of all, you didn't provide any info concerning what library you're using and where you got stuck.
So I'll just assume you're using FastLED, and since the issue isn't super complex, I can give you pretty much all the code you may need.

Looking at the drawing, the LEDs are positioned like it is one single strip.

The main line is 14 LEDs (LEDs 0-13), and at LED 10, we see 2x 5 LEDs (14-18 and 19-23), making it a total of 24 LEDs (the LED array starts counting at zero, so 0-23).

The base pattern looks like this, when initially skipping the fact that the LEDs fade out:

```0
1
2
3
4
5
6
7
8
9 + 14 + 19
10 + 15 + 20
11 + 16 + 21
12 + 17 + 22
13 + 18 + 23```

We can do this in code (fading/clearing of LEDs not yet included):

```  for(int i=0; i<14; i++) {
leds[i] = CRGB(0,255,0);

if(i>8) {
leds[i+5] = CRGB(0,255,0);
leds[i+10]= CRGB(0,255,0);
}

FastLED.show();
delay(speeddelay); // determines speed, higher number = slower effect
}```

So for LEDs 0 to 13, we set the LED to green.
If we reached LED number 10 (remember, we start counting at zero and not one, so LED 9, eg. >8, and up) we need to go sideways as well (14 to 18 and 19 to 23).

Next we need to add a fade to the code (you may need to experiment a little with the value "96" to get the desired amount of fade-out effect):

```  for(int i=0; i<14; i++) {
fadeToBlackBy(leds, 24, 96); // led array, number of LEDs, amount of darkening

leds[i] = CRGB(0,255,0);

if(i>8) {
leds[i+5] = CRGB(0,255,0);
leds[i+10]= CRGB(0,255,0);
}

FastLED.show();
delay(100); // determines speed, higher number = slower effect
}```

So,... all combined this should be something like this (untested, as I do not have my hardware handy at the moment), with the delay and color as a parameter:

```#define FASTLED_INTERNAL    // just used to mute the Pragma messages when compiling
#include "FastLED.h"
#define NUM_LEDS 24
CRGB leds[NUM_LEDS];
#define PIN 6

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

void loop()
{
cross_effect(100,96,CRGB(0,255,0));
}

void cross_effect(int speeddelay, int DarkfadeAmount, CRGB LEDColor) {

for(int i=0; i<14; i++) {
// values: led array, number of LEDs, amount of darkening

leds[i] = LEDColor;

if(i>8) {
leds[i+5] = LEDColor;
leds[i+10]= LEDColor;
}

FastLED.show();
delay(speeddelay); // determines speed, higher number = slower effect
}
}```

Again: untested, and you may need to tinker a little with the values.

(@Anonymous)
Joined: 1 second ago
Posts: 0

Thank you very much, it works great!

I was using neopixel, but now I also added fastled, because I didnt know similar method to "fadeToBlackBy". Is there maybe something similar for Adafruit_Neopixel?

Previously I just set the leds off like this:

```uint32_t off = strip.Color(0, 0, 0);

if (i >= loopLED) {
strip.setPixelColor((i - loopLED), off);
color = strip.Color(0, i - 5, 0);
}```

(@hans)
Joined: 10 years ago
Posts: 2554
Topic starter

You're right: NeoPixel doesn't have a function like that.
This is why I recommend most to use the FastLED library. It is more mature, faster and has more functions.

You could try to write your own code to mimic the FadeToBlackBy function for NeoPixel, but personally I would stick to FastLED 😊

In your code you set the LEDs to black. Is that what you were looking for? (since the animation suggested you'd want the LEDs to fade away instead of instantly going off)

(@Anonymous)
Joined: 1 second ago
Posts: 0

@hans because I like this fade effect, I will switch my whole program to FastLED, I think it will be more sustainable, than programming fade function by my own. (especially because I am not so good (yet) at it 🤣 )

(@hans)
Joined: 10 years ago
Posts: 2554
Topic starter

Sounds like a good plan. 👍 😉
I'll admit; I once started with NeoPixel as well until I noticed how much faster and better FastLED seems to be (especially noticeable with very long LED strips).

I hope the code works for you!

#### Like what you see and you'd like to help out?

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal (\$5, \$10, \$20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: