Getting Multiple lines of LEDs on in one loop

Hello all,

I’m working on my first Arduino Project, In this project there will be a video played on a Raspberry Pi. as soon as this video starts playing i’m sending a start command from the Raspberry to my arduino.
When the Arduino gets the start signal the LEDs will start moving from left to right.
Now my problem is that its takes quite some time to get the LEDs from left to right because one strip of LEDS contains 300 LEDS. So i tried to get two or three lines of LEDS running from left to right with a delay of a few seconds between them.

But i can’t find how i can program that.

My current code is

#include "FastLED.h"
#define NUM_LEDS 303 //350
#define PIN 6 
CRGB leds[NUM_LEDS];
int myCounter = 0;
int mySwitchPin = 4;
int pinvalue = 0;

void showStrip()
{
	FastLED.show();
}

void setPixel(int Pixel, byte red, byte green, byte blue)
{
	leds[Pixel].r = red;
	leds[Pixel].g = green;
	leds[Pixel].b = blue;
}

void setup()
{
	FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
	pinMode(mySwitchPin, INPUT);
}

void loop()
{
	meteorRain(0xff, 0xff, 0xff, 10, 50, false, 1);
	pinvalue = digitalRead(mySwitchPin);
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)

{
		{
		if (pinvalue == HIGH)
		{

			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)>1)) 
				{
					fadeToBlack(j, meteorTrailDecay);
				}
				}

				// draw meteor
				for (int j = 0; j < meteorSize; j++)
				{
					if ((i - j <NUM_LEDS) && (i - j >= 0))
					{
						setPixel(i - j, red, green, blue);
					}
				}

				showStrip();
				myCounter = ++myCounter;
			}
		}
		else 
		{
			myCounter = 0;
		}
	}
}



void fadeToBlack(int ledNo, byte fadeValue) {
	uint32_t oldColor;
	uint8_t r, g, b;
	int value;


	r = (r <= 10) ? 0 : (int)r - (r*fadeValue / 256);
	g = (g <= 10) ? 0 : (int)g - (g*fadeValue / 256);
	b = (b <= 10) ? 0 : (int)b - (b*fadeValue / 256);

	leds[ledNo].fadeToBlackBy(fadeValue);
}

I have tried to put in this part of the code in a second time, but when I don’t have any compile problems anymore and the code is uploaded to the Arduino, nothing happens.

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)>1)) 
				{
					fadeToBlack(j, meteorTrailDecay);
				}
				}

				// draw meteor
				for (int j = 0; j < meteorSize; j++)
				{
					if ((i - j <NUM_LEDS) && (i - j >= 0))
					{
						setPixel(i - j, red, green, blue);
					}
				}
void loop()
{
	meteorRain(0xff, 0xff, 0xff, 10, 50, false, 1);
	pinvalue = digitalRead(mySwitchPin);
}

meteorRain() expects pinvalue to have a meaningful value. Why are you only assigning it a meaningful value AFTER calling meteorRain()?

You need to a pay a visit to the fine folks at http://snippets-r-us.com for help with your snippets.

So, you suggest to simply swap those two?

TBosman:
So, you suggest to simply swap those two?

That would be the first thing to do.

The second thing to do is to check out the site I linked.

The third thing to do will become real obvious when you do the second thing.

The first code I posted is my full ‘working’ code at the moment. What i’m asking is how I can add something to my code to get a seconde line of LEDS working in the same loop.

The second part of code I posted was an example of the idea’s I tried but not succeed with.

My last idea was the following code:

#include "FastLED.h"
#define NUM_LEDS 303 //350
#define PIN 6 
CRGB leds[NUM_LEDS];
int myCounter = 0;
int mySwitchPin = 4;
int pinvalue = 0;

void showStrip()
{
	FastLED.show();
}

void setPixel(int Pixel, byte red, byte green, byte blue)
{
	leds[Pixel].r = red;
	leds[Pixel].g = green;
	leds[Pixel].b = blue;
}

void setup()
{
	FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
	pinMode(mySwitchPin, INPUT);
}

void loop()
{
	//pinvalue = digitalRead(mySwitchPin);
	meteorRain(0xff, 0xff, 0xff, 10, 50, false, 1);
	meteorRa1n(0xff, 0xff, 0x00, 10, 50, false, 1);
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)

{
		//if (pinvalue == 1)
		//{

	for (int k = 0; k < NUM_LEDS + NUM_LEDS; k++)
	for (int i = 101; i < NUM_LEDS + NUM_LEDS; i++)
			{

				// fade brightness all LEDs one step
				for (int j = 0; j<NUM_LEDS; j++)
				for (int l = 101; l<NUM_LEDS; l++)
					{
					if ((!meteorRandomDecay) || (random(10)>1)) 
				{
					fadeToBlack(j, meteorTrailDecay);
					fadeToBlack(l, meteorTrailDecay);
				}
				}

				// draw meteor
				for (int j = 0; j < meteorSize; j++)
					for (int l = 101; l < meteorSize; l++)
				{
					if ((i - j < NUM_LEDS) && (i - j >= 0))
					if ((k - l < NUM_LEDS) && (k - j >= 101))
					{
						setPixel(i - j, red, green, blue);
						setPixel(k - j, red, green, blue);
					}
				}

				showStrip();
				myCounter = ++myCounter;
			}
		//}
		//else 
		//{
		//	myCounter = 0;
		//}
}

void meteorRa1n(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)
{
		//if (pinvalue == 1)
		//{
			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)>1))
					{
						fadeToBlack(j, meteorTrailDecay);
					}
				}

				// draw meteor
				for (int j = 0; j < meteorSize; j++)
				{
					if ((i - j <NUM_LEDS) && (i - j >= 0))
					{
						setPixel(i - j, red, green, blue);
					}
				}

				showStrip();
				myCounter = ++myCounter;
			}
		//}
		//else
		//{
		//	myCounter = 0;
		//}
}



void fadeToBlack(int ledNo, byte fadeValue) {
	uint32_t oldColor;
	uint8_t r, g, b;
	int value;

	r = (r <= 10) ? 0 : (int)r - (r*fadeValue / 256);
	g = (g <= 10) ? 0 : (int)g - (g*fadeValue / 256);
	b = (b <= 10) ? 0 : (int)b - (b*fadeValue / 256);

	leds[ledNo].fadeToBlackBy(fadeValue);
}

What i’m asking is how I can add something to my code to get a seconde line of LEDS working in the same loop.

I really do not understand what you mean by “a second line of LEDs”. A second strip?

	for (int k = 0; k < NUM_LEDS + NUM_LEDS; k++)
	for (int i = 101; i < NUM_LEDS + NUM_LEDS; i++)
			{

				// fade brightness all LEDs one step
				for (int j = 0; j<NUM_LEDS; j++)
				for (int l = 101; l<NUM_LEDS; l++)

EVERY for statement should have open and close curly braces. Put them in, and then use Tools + Auto Format. Then, if the code still looks right to you, post it again.

Those 4 nested for loops do not bear even the remotest appearance of right to me.

This is what I currently have. as you can see it takes some time for the lights to finish the whole LED strip. So what I want is that before the lights finish the whole strip, some new lights start at the beginning. so that it will look like there are two different 'lines' going through the LED strip.

And I will change the code.