After much cautious soldering, I've got my first decent project finished. The set-up is my arduino (pins: digital 10, 11, 12, 13 & analog 5v and GND). This is hooked up to a 4051 (as a demux) which then runs out 8 outputs to leds (common cathode) with appropriate resistors (on the anode of course).
A number of questions come to mind:
-
The LEDs are slightly dim. Because I'm rapidly flipping through them, I assume they aren't getting enough current. Are there formulas to calculate a lower resistor value that takes into account the switching frequency?
-
Are there advantages or disadvantages to which end of the LEDs are common? (anode vs cathode)
-
I've seen people mention TLC5940s. Would these be something to look into for large groups of LEDs like this one?
For the curious my sketch looks like this:
/* muxProg v1.0
* Author: Johnny Ferguson
*
* Uses a 4051 to make a simple programmable LED Array
*/
#define PROG_LENGTH 98
// Global Vars
/// Pinout
int ledOut = 13; // led output
int selA = 12; // select A
int selB = 11; // select B
int selC = 10; // select C
/// Select
int bin [] = {000, 1, 10, 11, 100, 101, 110, 111}; // binary values for mux select
int selValue = 0; // holds the value for select bit bitshifting
int sa, sb, sc = 0;
int ledVal = 0;
int portBOut = 0; // pins 8-13
unsigned int pattern [PROG_LENGTH] = {
B00000001,
B00000011,
B00000111,
B00001111,
B00011111,
B00111111,
B01111111,
B11111111,
B11111110,
B11111100,
B11111000,
B11110000,
B11100000,
B11000000,
B10000000,
B00000000,
B10000000,
B11000000,
B11100000,
B11110000,
B11111000,
B11111100,
B11111110,
B11111111,
B01111111,
B00111111,
B00011111,
B00001111,
B00000111,
B00000011,
B00000001,
B00000000,
B00000001,
B00000011,
B00000111,
B00001111,
B00011111,
B00111111,
B01111111,
B11111111,
B11111110,
B11111100,
B11111000,
B11110000,
B11100000,
B11000000,
B10000000,
B00000000,
B10000000,
B11000000,
B11100000,
B11110000,
B11111000,
B11111100,
B11111110,
B11111111,
B01111111,
B00111111,
B00011111,
B00001111,
B00000111,
B00000011,
B00000001,
B00000000,
B00000000,
B00000000,
B11111111,
B11111111,
B00000000,
B00000000,
B11111111,
B11111111,
B00000000,
B00000000,
B11111111,
B11111111,
B11111111,
B11111111,
B00000000,
B00000000,
B00000000,
B00000000,
B11111111,
B11111111,
B00000000,
B00000000,
B11111111,
B11111111,
B00000000,
B00000000,
B11111111,
B11111111,
B11111111,
B11111111,
B00000000,
B00000000,
B00000000,
B00000000,
};
// setup
void setup(){
// Set pins 10-13 for output
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
}
// main loop
void loop(){
for(int j = 0; j < PROG_LENGTH; j++){
for(int i = 0; i < 8; i++){
// load selValue from binary array
selValue = bin[i];
// bitshift and mask to get appropriate values
sa = selValue & 0x01;
sb = (selValue >> 1) & 0x01;
sc = (selValue >> 2) & 0x01;
// get the on/off bit for this part of the pattern, then use port manipulation to write select values (faster than digitalwrite)
ledVal = ((pattern[j] >> i) & 0x01) ? 1 : 0;
portBOut = B00111100 & ((ledVal << 5) | (sa << 4) | (sb << 3) | (sc << 2));
PORTB = portBOut;
// to stop the animation from playing way too fast
delay(1);
}
// stops the last LED in the chain from staying on bright between animation frames
PORTB = B00000000;
delay(1);
}
}
I'm thinking for the next sketch I do with this board, I'll write the program so my array can specify a time in milliseconds for each frame to display. I'd also like to avoid the use of delay as it's just sloppy in general (but was a great way to get this thing tested).