Yes, it's possible with an array, but you could do something like that, instead of an array for each mode, have a single integer:
// the pins where each led is connected, in reverse order
const uint8_t LED_Pins[] = { 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
// set a mode using a single int
const uint16_t MODE_1 = 0b111101101111; // this is your example (middle LEDs OFF) in one line
void SetLEDArrayMode( uint16_t mode )
{
for (uint8_t i = 0; i < 12; i++)
digitalWrite( LED_Pins[i], bool( mode & (1 << i) ) );
}
void setup()
{
SetLEDArrayMode( MODE_1 );
}
Note, the reverse order is because using this method, the bits are read in reverse order too. But if your modes are always "symmetrical", then the order of the pins array will have no importance.. 8)
I'm just trying to implement your example into some simple code to control LED's via a TLC5940 driver IC
I'm getting confused though, instead of using digital write I need to send a 12bit value to control the brightness of the LED's.
How could I write an array for the values to be sent i.e. const uint16_t MODE_1 = 4095, 4095, 1000, 0, 0, 500, 700.... and send those values to the 5940?
lloyddean:
If it helps keep in mind you can visualize the result with this layout for building your patterns and it will still compile.
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?
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?