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 no translation for that post!



Ws2811 10×10 panel
 
Share:
Notifications
Clear all

[Solved] Ws2811 10×10 panel

38 Posts
2 Users
1 Reactions
10.7 K Views
(@darek)
Eminent Member
Joined: 4 years ago
Posts: 21
Topic starter  

Hi guys . Like I said earlier I've got 10×10  panel and I would like to make from leds number 1,2,3,4,5,6,7,8,9,10,11,20,21,30,31,40,41,50,51,60,61,70,71,80,81,90,91,92,93,94,95,96,97,98,99,100 still lightning frame. Which I did in void setup 

Led.setpixelcolor (0,ledcolor(255,0,0))

Led.setpixelcolor(1,ledcolor(255,0,0))

Led.setpixelcolor(2,ledcolor(255,0,0))

.......... until 

Led.setpixelcolor(99,ledcolor(255,0,0)).

Then it works but the rest of leds I would like toput meteor animation. I tried to copy meteor animation to void loop but is not working. I don't really know how the code should look like with those (inside lighting frame). Anybody knows how could i do it and can help a bit I'll be very appreciate.  


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796
 

Hi Darek,

I do not have a 10x10 matrix available, so I can only help with theoretical answers or untested code 😊 

Note: it would be helpful if you post the code you have, and it would be good to know if you rely on the FastLED library (recommended) or the NeoPixel library.

By the looks of it we have 2 "elements"

1) The frame, which you already got covered (note: you can shorten you code by using 2 for-loops).

For example:

for(int i=0; i<=10; i++) {
  Led.setpixelcolor(i, ledcolor(255,0,0));
  Led.setpixelcolor(90+i, ledcolor(255,0,0));
}

for(int i; i=2; i<=8) { 
  Led.setpixelcolor(i*10, ledcolor(255,0,0));
  Led.setpixelcolor( (i*10)+1, ledcolor(255,0,0));
  Led.setpixelcolor( (i*10)+8, ledcolor(255,0,0));
  Led.setpixelcolor( (i*10)+9, ledcolor(255,0,0));
}

 

2) The meteorrain effect in the unused leds in the middle.

An answer for this would need some more input. For example: how would you like the meteor rain to run?
From top to bottom? Zig-zag? Left to right? 


   
ReplyQuote
(@darek)
Eminent Member
Joined: 4 years ago
Posts: 21
Topic starter  

Hi Hans. Thanks for your reply. 

I'm  newee with arduino coding so i just trying  what i learn thru Internet.  But i can see you know that stuff very well so if you could help me I'll be very appreciate.  Past me yuor Paypal details mate so i could send you some support for beer . 

Basically i would like to try all three version which you proposed ( left to right,up and down, and zig zag ) if its possiblle.  And if you could explain me what does the code do in the void loop ( i mean like comments) it cuold help me to understand it easier.  Like for example I know first loop for which you said me to shorten the code(is fir the two external columns), but I'm confused why in second for loop   i is without the value.  Than why second i is=2 and third i is < 8 because the leds ( the top and bottom rows as frame)between columns.??

Than why set.pixelcolor is multiplying by10 ,  than +1  , than +8  and + 9 ??

I hope you might to help me to understand this better. 

Thanks for your advice  Hans.

Please don't forget past me your PayPal details.  

 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796
 

oooh beer is always good 😊🍺🍻 - my PayPal info can be found just below the edit box where you're writing your reply, and in the upper left corner of the page.
Note: sponsoring is always very much appreciated, but not a requirement 😊 

And don't worry about being new to the Arduino and LEDs - we all started somewhere right? 😉 

For-loops ...

for(int i=0; i<=10; i++) {
  Led.setpixelcolor(i, ledcolor(255,0,0));
  Led.setpixelcolor(90+i, ledcolor(255,0,0));
}

So in this example the variable "i" counts from 0 to 10 which means it sets the leds like so (the top row and the bottom row of your 10x10 matrix):

0, 90, 1, 91, 2, 92, 3, 93, 4, 94, 5, 95, 6, 96, 7, 97, 8, 98, 9, 99, 10, 100

For the second loop we see something similar, however we now need the far left and far right leds (assuming 21, 31, 42 etc) and the far right (20, 30, 40).

So I tried to capture this sequence with that: 10, 11,20,21,30,31,40,41,50,51,60,61,70,71,80,81 - but I made a mistake in my code I think. 🙄 

Better would have been:

for(int i=1; i<=8; i++) {
  Led.setpixelcolor( i*10, ledcolor(255,0,0) ); // 10, 20, ..., 70, 80
  Led.setpixelcolor( (i*10)+1, ledcolor(255,0,0) ); // 11, 21, ..., 71, 81
}

  

So 1x10, and (1x10)+1, 2x10 and (2x10)+1, 3x10 and (3x10)+1 etc.

Note to self: don't write code when I haven't had enough coffee yet 😉 

Considering you have a "work space" of 8x8 (10x10 minus the borders), I'm not sure which one would look good.
Either way, we can either use some math or a predefined matrix (read: array) with the LEDs we can use.
I'll have to get back on that one, probably tomorrow. I'm a little exhausted of my work from today.


   
ReplyQuote
(@darek)
Eminent Member
Joined: 4 years ago
Posts: 21
Topic starter  

Hi Hans thanks for explanation above . Now this is for me more clearly understand.  So how can I use "work space" now? 

Is it enough if i will copy some of your animation codes and paste in void loop?  

Cheers mate sent  you something for beer. I'm very appreciate for your help.

 

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796
 

Thanks for the beer donation 😁  - it will be used wisely hahah 😉 

I do not have you full code (please consider posting it here either in a message or as an attachment), so I'll give you an idea what I'm thinking off.

The Leds are stored in an array, and this is how we change the colors of each led: change the entry in the array.
Now arrays can be confusing (see my little programming course for the Arduino on Arrays) - in this case, think of it as a list of variables, accessible by an index.
It is a little more complicated than that, since most led libraries add some extra functions to it, but we can ignore that for now.

The idea I have is to define another array, holding the indices of the LEDs that we are allowed to use (the workspace).
So basically all LEDs minus "1,2,3,4,5,6,7,8,9,10,11,20,21,30,31,40,41,50,51,60,61,70,71,80,81,90,91,92,93,94,95,96,97,98,99,100".

This array will be a list of 8x8 = 64 items.
You may remember that most functions rely on the NUM_LEDS constant, so for our "translation" array we should define something like that as well.
For example: NUM_WORKSPACE_LEDS 

#define NUM_WORKSPACE_LEDS 64

 

Next we need to define out translation array:

int Workspace[NUM_WORKSPACE_LEDS];

 

This way however, the array is empty, but we can pre-populate it manually or with a few loops.

Manually (way in the beginning of your sketch, where the "#define" are as well):

int Workspace[NUM_WORKSPACE_LEDS] = { 12, 13, 14, 15, 16, 17, 18, 19, 
                                      22, 23, 24, 25, 26, 27, 28, 29, 
                                      32, 33, 34, 35, 36, 37, 38, 39, 
                                      42, 43, 44, 45, 46, 47, 48, 49, 
                                      52, 53, 54, 55, 56, 57, 58, 59, 
                                      62, 63, 64, 65, 66, 67, 68, 69, 
                                      72, 73, 74, 75, 76, 77, 78, 79, 
                                      82, 83, 84, 85, 86, 87, 88, 89  };

 

So the array only holds the leds in the workspace.

Now, when working with LEDs, we need to "translate" the position to a position in the workspace.

As an example, this is how we used to fill all out leds to white:

for(int i=0; i<NUM_LEDS; i++) {
  Led.setpixelcolor( i, ledcolor(255,255,255) );
}

 

If we only want to fill the workspace, we have to change it to this:

for(int i=0; i<NUM_WORKSPACE_LEDS; i++) {
  Led.setpixelcolor( Workspace[i], ledcolor(255,255,255) );
}

 

So when we call for "Workspace[0]", we get the value "12" returned from the array - we translated the first led (0) to its actual position (12).
Same for Workspace[1], which returns 13, etc etc.

Before we proceed I'd recommend testing this in your code, I do not have a 10x10 matrix to test. 😊  (I do have beer though! 😁🍺 )

 

Now the next step would be applying this to the meteor-rain effect, but since you do not seem to be using my code (from the LED effects project), I can only guess what it could be.
Here an illustration how this can be done, based on my LED Effects project, where the meteor-rain effect looks like this.
We see the usual NUM_LEDS and that we call our leds based on a number (index).

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  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) ) {
        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();
    delay(SpeedDelay);
  }
}

 

To make this work only for the workspace, we need to replace:

- NUM_LEDS with NUM_WORKSPACE_LEDS,
- and every call where we need the LED index needs to be translated with our Workspace array (eg setPixel( led_index, color) becomes setPixel( WorkSpace[led_index], color) ).

I hope that makes sense.

!! Pay attention to the square brackets ( [ and ] ) for arrays, versus the round brackets ( ( and ) ) used with functions. !!

Also note that setting all LEDS to one color now requires you to think for a second and decide wether this should affect all leds or just the LEDs in the workspace (see comment in the code below).

Modifying the code as such will result in something this (which will make the effect go zig-zag):

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  // setAll(0,0,0); should not be used as it would erase your border
  // instead only make workspace black like so:

  for(int i = 0; i < NUM_WORKSPACE_LEDS; i++) {
    setPixel(Workspace[i], 0, 0, 0);
  }
  
  // optional, to make black workspace visible:
  // showStrip();

  for(int i = 0; i < NUM_WORKSPACE_LEDS+NUM_WORKSPACE_LEDS; i++) {
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_WORKSPACE_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(Workspace[j], meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_WORKSPACE_LEDS) && (i-j>=0) ) {
        setPixel(Workspace[i-j], red, green, blue);
      }
    }
   
    showStrip();
    delay(SpeedDelay);
  }
}

 

You can see that NUM_LEDS simply get replaced by NUM_WORKSPACE_LEDS and each LED index is translated thought our Workspace array.

I hope this makes sense 😊 

Caution though:

1) Do not blindly copy this code since your code seems to rely on something else, maybe the NeoPixel library? (I'd recommend FastLED though, as it is faster and more mature than NeoPixel)
2) I hope I didn't overlook any code where the index value for Workspace exceeds the array size (which could cause an error).
3) Again: untested code.


   
ReplyQuote
(@darek)
Eminent Member
Joined: 4 years ago
Posts: 21
Topic starter  

Hi Hans. 

Thank you very much for explanation of this project to understand how this code should be build. That is what I was looking for.  Now i have some point where I can testing and practising coding. I'm really appreciate for your help.  I'll try to test this code when I'll find little bit of time. Because at the moment got to much work.

 

Yes I'm using Fastled and Neopixel libraries  and also I was trying all of  your led effects which are really good. 

 

I definitely will look your programming  course. 

The other reason why I'm trying to do testing and practising this project because I might to do someting like that video 

https://youtu.be/U5du7moM3yo.  

And if i will manage to do it will you recommend using pull up or pull down RC filter. If yes what the capacitor and resistor value will you recommend Hans?

Again thanks for your advice and enjoy your beer Hans. 

If not tha distance and the lockdown we could go down to the pub for beer or two . 

Cheers mate. 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796
 
Posted by: @darek

I'm using Fastled and Neopixel libraries

I'd recommend sticking with just one library. In my experience, FastLED is the most mature and faster than NeoPixel (especially visible with larger quantities of LEDs). 😊 
I assume you're already not mixing them. By using only one library, you'll also get more familiar with the unique functions offered by that particular library. FastLED for example ha some very powerful functions (the documentation is very extensive and not always as easy to read, but tons of folks use FastLED, so there are plenty examples out there).

Testing is always a good way to learn - that's how I started as well 😁 
I usually tinker around with small parts of a project, and when I'm satisfied with testing, I'll start building the project in a new empty sketch.

As for the video: unfortunately, it shows and error when I try to play it .... (An error occurred. Please try again later. (Playback ID: YWdraLGI8ocQpAKM))

I'm not sure what RC filter you're referring to ... was this mentioned in the video?
The only extra components I'd be using for a setup like yours is a 470 Ohm resistor for the LEDs, and in case you're using switches a resistor to avoid the button bounce effect.

I too would have preferred stepping into a pub for a beer 😁 

Let me know when you have question - I'd be happy to assist where I can.


   
ReplyQuote
(@darek)
Eminent Member
Joined: 4 years ago
Posts: 21
Topic starter  

Hi Hans.

I'm amateur with Leds 🤣 .Just noticed AdaNeoPixel codes doesn't work with Fastled. 

Iwas using  FastLed earler as a examples available in libraries so I didn't know they don't match with another libraries..

 

So I came to this point . One led was ON Glow

#include <FastLED.h>

#define NUM_LEDS 100

#define PIN 6

CRGB leds [NUM_LEDS];

 

void setup () {

FastLED.addLeds<WS2811, PIN,RGB >(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop()
{

leds[2] = CRGB:: Red;

FastLED.show();

}

then I was thinking .If I can glow one led i should be able to glow all of them or 10 of them but......I finished on 10 of them .

. Then I used 

"for"loop  try to glow line of 10 leds. it was work for 10 leds.    But after this i was stuck. tried to do (90+i)

  Led.setpixelcolor(i, ledcolor(255,0,0));
  Led.setpixelcolor(90+i, ledcolor(255,0,0));
}

but that configuration will works only  for  AdaFruit   (I think). Didn't tested.

but commands looks like from NeoPixel.

My matrix looks like this

        Data Out< 9,8,7,6,5,4,3,2,1,0,  <Data in <<<<<<<<<<<<<

 >   Data in >10............................19> Data Out > \/

  \/<DataOut<29 <<<<<<<.....  20    <   Data In  <

                        30>>>>>>>>>39

                        49<<<<<<<<<40

                        50>>>>>>>>>59

                        69.<<<<<<<<..60

                        70>>>>>>>>>79

                        89<<<<<<<<<80

                        90>>>>>>>>>99

Well drawing this scheme I forgot what i was asking for  haha.

It took me to  much time 🤣 🤣 🤣 🤣 to do this . Just have a laugh at myself .

but let get back to subject...  FastLed looks much easier to coding but I don't know Where should I go after first line I glow up. And I wouldn't like  you Hans write full code for me ,because I. will not learn anything ..

But some clue or stronger clue which I can use for Fastled..

After reading your Array course I will have some ideas.But same time I have so many question marrks , because is not one line of Leds but matrix (10x10 panel).


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796
 

Haha, well, we all have to stumble a few times to learn - I have had similar experiences 😉 
And ... wanting to learn yourself is indeed the only and best way!

Maybe this is helpful to get started with FastLED:

Call the library (as usual, and I added a line before that which isn't required, it just suppresses a message during compiling:

#define FASTLED_INTERNAL    // just used to mute the Pragma messages when compiling
#include "FastLED.h"

// some LED details
#define NUM_LEDS    60      // Number of LEDs in strip
#define LED_PIN     4       // GPIO pin we used for the strip
#define BRIGHTNESS  255     // Default LED brightness.
#define LED_TYPE    WS2812  // Type of LED strip
#define COLOR_ORDER GRB     // Color order LED stri

 

 Define the led array (after the define's):

CRGB leds[NUM_LEDS];

 

In void loop we setup the LEDs for FastLED and clear them right away (set to black, not required by the way)

// Initialize LED strip 
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.clear(true); // clear LEDs and Show

 

 A few handy functions:

FastLED.clear(true); // set all leds to black

// Set a LED to red
leds[lednumber] = CRGB(255,0,0);

// alternative:
leds[ledbumber] = CRGB::Red


FastLED.show(); // make changes visible (Neopixel has a similar function)

fill_solid( leds, NUM_LEDS, CRGB(0,0,255)); // fill the leds with a color (blue)

 

Note: FastLED has a TON of extra functions that help with working with LEDs.
The FastLED documentation is quite extensive and can be a little overwhelming, feel free to ask if you have questions 😊 

As for the matrix: from what I understand, and keep in mind that I do not have a LED matrix laying around, the LEDs are placed in sequence, so the first row are the LEDS 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and the next row is 10, 11, 12 ,... ,18, 19, etc.
If that is correct, then we do not need a X,Y matrix, since the matrix doesn't work like that to begin with (correct me if I'm wrong!).


   
ReplyQuote
(@darek)
Eminent Member
Joined: 4 years ago
Posts: 21
Topic starter  

Hi Hans. 

Thaks again for correction my mistake with matrix( which is not). Didn't have clue matrix doesn't work like that. So basically I've got strip of 100  leds which I divide them on 10 rows.  Is that make more complicated to do what I was askig for ( border leds glow constantly) and the rest will do others things??

Iwas trying last night to light all leds this way

Leds[NUM_LEDS]=CRGB::Red; . 

If I understand this correctly in [] brackets  will be NUM_LED   which is defined  on beginning of the sketch NUM_LED 100  so all of leds should be lighting.  But while compiling came error on that line which is above.

Another thing is can I try to use those arguments which you show me earlier something like thst 

for(int i=1; i<=8; i++) {
  Led.setpixelcolor( i*10, ledcolor(255,0,0) ); // 10, 20, ..., 70, 80
  Led.setpixelcolor( (i*10)+1, ledcolor(255,0,0) ); // 11, 21, ..., 71, 81
}

But of course in Fastled library style.?? 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796
 

Haha, don't consider it a mistake ... I would have expected it to an X,Y matrix as well.
Again: this still may be the case, as I do not have a LED matrix laying around.
However, the code you had suggests that the matrix is indeed 100 LEDs in a line, where each block of 10 represents a row.

It is good to copy and paste error messages - it becomes very difficult to see and guess if it is a simply typo (happens to me all the time) or something else.

When calling "Leds[NUM_LEDS]=CRGB::Red;" you have to keep in mind that NUM_LEDS represents the number of LEDs (100 in your case). However, "Leds" is and array, and those start counting with 0 where as we humans start counting with 1.

So when we humans count, we count 1, 2, 3, ... NUM_LEDS.  ( = 1 - 100)
An array however counts like this: 0, 1, 2,... (NUM_LEDS-1).  ( = 0 -99)

So the array will not have the element you're referring to (Leds[NUM_LEDS]).
The last LED in the array would be Leds[NUM_LEDS-1].

Having said that, I doubt the compiler would catch this, so the problem may be something else as well.

For example: did you call it "Leds" or "leds" or "Led" since these would be different variables!

Assuming you called it "Leds", your code question would look like so:

...
CRGB Leds[NUM_LEDS];
...


for(int i=1; i<=8; i++) {
  Leds[i*10] = CRGB(255,0,0) ); // 10, 20, ..., 70, 80
  Leds[(i*10)+1] = CRGB(255,0,0) ); // 11, 21, ..., 71, 81
}

 

Note: in most sketches the variable is called "leds". However, as long as you use the variable name consistent, it doesn't really matter what you call it.

The line "CRGB Leds[NUM_LEDS];" dictates what it's called.

 


   
ReplyQuote
(@darek)
Eminent Member
Joined: 4 years ago
Posts: 21
Topic starter  

Hi Hans .

 

Thanks for a clue what  I could mess up in my sketch. I'll try to write that code again  . I'm pretty sure your advice will work . I forgot about -1. 

NUM_LEDS represents 100 leds.  So counting from 0 to 99 for compiling  will be visible as 100 leds.  Got it 👍 

Thanks  a lot. 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2796
 

You're welcome 😊 

Feel free to ask if you run into an issue. I'd be happy to help if I can.


   
ReplyQuote
(@darek)
Eminent Member
Joined: 4 years ago
Posts: 21
Topic starter  

Hi Hans.

I was thinking how to add push button to your Ledstrip effects which are amazing. For example bouncing leds. How complicated and how much the code must be changed to do something like push the button one led bounce push another time second led bounce etc. Or if button will push longer than led will bounce higher.  

Another what I was thinking if those three bouncing leds can be spread on three different stripes and bouncing differently.  And how situation looks like to add push button to each of your Ledstrip effects. Is that a lot of modification of the code or is simply thing?

 

P.S.  I also would like to send you ledmatrix 16 × 16 so will be easier to testing  for example project which we was discussed earlier. Let me know Hans how can I past this matrix. 


   
ReplyQuote
Page 1 / 3
Share: