Go Down

Topic: 4x3 led grid array function? (Read 998 times) previous topic - next topic

dtokez


If it helps keep in mind you can visualize the result with this layout for building your patterns and it will still compile.

Code: [Select]

uint16_t n = 0b0000/   // ignor
             111/
             101/
             101/
             111;



Les, that looks great and very good for visualisation! I still can't work out how to send the 12 bit values to the TLC chip though instead of a 1 or a 0?

lloyddean

#6
Dec 28, 2012, 06:44 pm Last Edit: Dec 29, 2012, 01:33 am by lloyddean Reason: 1
I have no way  of knowing how you've wired the 16 channels to the LED's so pattern may be reversed

Untested and uncompiled because I'm to lazy to download the driver library to compile against.

Code: [Select]

#include "Tlc5940.h"

const uint16_t pattern = 0b0000/   // ignore these 3-bits
                        111/
                        101/
                        101/
                        111;


void SetLEDArrayMode(uint16_t pattern, uint16_t luminance)
{
   for ( int mask = 0b0000100000000000, chan = 0; mask; mask >>= 1, chan++ )
   {
       Tlc.set(chan, ((pattern & mask) ? luminance : 0 ));
   }
}

void loop()
{
   // 12-bit luminance, 0 - 4095

   int luminance   = 4095;                 // full brightness
   SetLEDArrayMode(pattern, luminance);
}

void setup()
{
   Tlc.init(0);
}


dtokez

Hi, thanks for that! I can't get my head around how it would work though (not tried it yet).

What does the mask stuff do?

lloyddean

#8
Dec 29, 2012, 06:20 pm Last Edit: Dec 29, 2012, 06:32 pm by lloyddean Reason: 1
I always place URL's inline and not as links so that they may be seen before use.

Please see this reference page <http://www.cplusplus.com/doc/tutorial/operators/> and read about

'?:'    conditional operator
','     comma operator
'&'     bitwise operator, specifically 'and'
'>>'    bitwise operators, shift-right
'>>='  compound assignment operator

and finally this page <http://www.cplusplus.com/doc/tutorial/control/> and the section "The for loop"


dtokez


I have no way  of knowing how you've wired the 16 channels to the LED's so pattern may be reversed

Untested and uncompiled because I'm to lazy to download the driver library to compile against.

Code: [Select]

#include "Tlc5940.h"

const uint16_t pattern = 0b0000/   // ignore these 3-bits
                        111/
                        101/
                        101/
                        111;


void SetLEDArrayMode(uint16_t pattern, uint16_t luminance)
{
   for ( int mask = 0b0000100000000000, chan = 0; mask; mask >>= 1, chan++ )
   {
       Tlc.set(chan, ((pattern & mask) ? luminance : 0 ));
   }
}

void loop()
{
   // 12-bit luminance, 0 - 4095

   int luminance   = 4095;                 // full brightness
   SetLEDArrayMode(pattern, luminance);
}

void setup()
{
   Tlc.init(0);
}




Hi all. Just working on this idea again but having no success. I can't get the TLC to do anything using either the above code of the code below. How does it work or how should it work? Just want to be able to set a pattern with each bit being a TLC output ie.

111
101
101
111

not sure how that could be implemented into TLC pins?

Code: [Select]
#include "Tlc5940.h"

const uint16_t pattern = 0b0000/   // ignore these 3-bits
111/
101/
101/
111;


void SetLEDArrayMode(uint16_t pattern, uint16_t luminance)
{
 for ( int mask = 0b0000100000000000, chan = 0; mask; mask >>= 1, chan++ )
 {
   Tlc.set(chan, ((pattern & mask) ? luminance : 0 ));
 }
}

void loop()
{
 // 12-bit luminance, 0 - 4095

 int luminance   = 4095;                 // full brightness
 SetLEDArrayMode(pattern, luminance);
 Tlc.set(pattern, luminance);
 Tlc.update();
 delay(100);
}

void setup()
{
 Tlc.init(0);
}

Go Up