Page 1 of 1
Forum

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 most likely no translated for the post!




LEDs: How to change...
 
Share:
Notifications
Clear all

LEDs: How to change the order of the LEDs


 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1958
Topic starter  

A question posted by Khammel under the LED Effects article:

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 

This topic was modified 1 month ago by Hans

ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1958
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.


ReplyQuote

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: