Jump to content

arduino question. ws2812b led matrix.

Jstagzsr

im not sure where to put this so i put it in general.


i have an arduino uno.
i built the matrix. 14x10

im ultimatekly trying to make a clock that has cool colorful animations in the background

i have no idea where to find out how to do this.. i have sweet animations "playing" on it now. but i cant find where to build (code) the clock. i cant even find anything on programming ws2812b matrixes.

any help would be appreciated

Link to comment
Share on other sites

Link to post
Share on other sites

  • 4 weeks later...

there is no standard to wire a matrix, so just the matrix builder knows how the thing would be a function for the calculation of the adress like:

#define ROWS XX
#define COLUMS YY

int GetAdress(int row, int colum)
{
	if((row<ROWS)&&(rows>=0)
    {
    	if((colum<COLUMS)&&(colum>=0)
        {
        	return (colum+COLUMS*(row-1));
        }
    }
    return -1; //if wrong insert -> ERROR Code
}

Edit:

the circuit/adresses would be:

|  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7|

----------------------------------------

|  8 |  9 | 10 | 11 | 12 | 13 | 14 | 15 |

...

Edited by tankhunter8192
Circuit added
Link to comment
Share on other sites

Link to post
Share on other sites

You have to stop thinking of them as matrices or something complex, it's just a string of leds.

It's best to start right from the beginning. In your case, if you want 14 wide, 10 tall, you'd arrange the led strips like this:

 

0 , 1, 2, 3, 4, 5, 6, 7, 8 , 9 , 10, 11, 12, 13 , 14  -> connect to 15

28,27,26,25,24,23,22,21,20,19,18,17,16,15    28 connects to 29

29......   and so on until you get to 139, for a total of 140 leds.

 

Your Arduino Uno microcontroller should have 2 KB of SRAM, which means you could simply use 4 bytes for each led, one for the brightness and three for each color (red, green and blue), so it would be a 140x4 bytes = 560 bytes... so your array would be from 0 to 559

If your brightness is gonna be a set value for all leds, then you'd have only 3 bytes per led, so 140x3 = 420 bytes... your array is [0..419]

 

Or, if you want to save memory, you could use only 1 bytes for each led or 4 bits for each led, where the byte or the 4 bits are an index in a color palette (a separate array, from 0 to 15 if you use only 4 bits, 32 or whatever amount you want up to 256 if you use a full byte)

 

If the first line is 0, and the first led is 0, and the bottom corner led is 13, 9 then it's super simple to calculate where to put the color data into the array


 

x = 0..13 
y = 0..9

offset = y * 14
if x == 0 or y == 2 or y == 4 or y == 6 or y == 8 then offset = offset + x
if y == 1 or y == 3 or y == 5  or y == 7 or y == 9 then offset = offset + 14 - x

offset = offset x 4  (you multiply with 4 because you have 4 bytes for each led)

So for example, for (2,1)  -- the third led on the second line you get :
 

offset = 1 * 14

y is 1 so you go with 2nd if, so  offset = offset + 14 - x => offset = 14 + 14 - 2 = 26 ... which is correct as you can see above

last, offset = offset * 4  = 26*4 = 104

So you store brightness at 104 position in array, red at position 105 , green at position 106 and blue at position 107 in your array.

If your brightness is global, then you don't have to store in array for each led, so you can use only 3 bytes for each, so then you multiply offset by 3 and  position offset is red, offset +1 is green, offset +2 is blue

 

When you want to refresh the whole panel, you can simply do a for i = 0; i < number of bytes in array; i=i+4  ... send the four bytes on the pins using fastled library or whatever.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×