# LEDs: How to change the order of the LEDs – – 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!

LEDs: How to change...

Share:
Clear all

# [Solved] LEDs: How to change the order of the LEDs

2 Posts
1 Users
0 Reactions
2,414 Views
(@hans)
Joined: 11 years ago
Posts: 2714
Topic starter

How do you re-order the initial array or string of led’s before it is passed to rest of program?

Typical program asks number of leds and then labels initial string ordered range

Led array => 1,2,3,4,5,6…49,50

But what if I want a different led order because it’s a 3D non linear shape, and want my string ordered

Led array => 5,37,2,34…21,1

What’s the syntax or coding that allows me to put the led strip in any order I like before passing to automated programs? I feel like I should be able to use some sort of cross list or cross mapping?

Using FastLED, or WS2812fx library

Topic Tags
(@hans)
Joined: 11 years ago
Posts: 2714
Topic starter

I think there are 2 possible methods you can apply to accomplish this;

Option 1 -- Use math

Now this trick only works when there is a certain logic to determine the correct position.
For example, when the LEDs are placed in a matrix. In that case you can calculate the actual position based on column and row.

In your example, I do not recognize a pattern, so this may not apply for that situation.

Option2 -- Make a translation matrix

Using FastLED we define an array for the LEDs, where the index is the n-th LED on the strip (eg. Led array => 1,2,3,4,5,6…49,50).

`CRGB leds[NUM_LEDS];`

The translation array basically is an array of integers (see also my article on Arrays in the Arduino course).

`int translate[NUM_LEDS];`

This array we need to populate with the order they are actually in, eg:

`in translate[NUM_LEDS] { 5,37,2,34…21,1 }; // fill in the missing numbers of course`

Now, normally we'd set a LED color based in the index, which now needs to be translated.

Original call:

`leds[i] = CRGB::Red;`

Call with translation:

`leds[ translate[i] ] = CRGB::Red;`

So as an illustration: we want the 4th LED (4) to be set to Red. However the 4th LED is actually #34. (from Led array => 5,37,2,34…21,1)
Here: "translate[4]" will actually return 34, which we use as the index for the actual "leds" and the correct LED will be called.

Share: