The Thread and the Story
Hey guys,
So I couldn't find a good code to charlieplex a 30 led Array and so through some adaptation of what I could find I made my own. I wanted to make something easy and versatile to use for anyone else trying to do the same thing as me. I will update the code the goals at the top of this topic. So if anyone or I add anything useful in the thread I'll update it to the top.
So far I've only seen charlieplexes that light each light for a fraction of a second relative to the number of lights, and moves on to the next light in the array. In my opinion this might be acceptable for arrays of 2x3, or 3x4, but not 5x6 as at best an LED is lit for 1/30th of the time.
What I've Done
-
Currently I've coded a standard 5x6 charlieplex test and have it up and running. It starts at the top left and scans down and moves to the next row to the right
-
I've also separately coded to light each column at one time (column A, column B, column C, column D)
-
Although virtually useless, I was playing around and coded each column minus one light (!A1, !A2, !A3, etc.) This was mainly done as a proof of concept (and I played around more to do multiple unlit lights in a row, but didn't to a complete series so I didn't keep them).
What I'm doing/My Goals/Things I could use help with
-
My goal is to make a system that will allow me to have it flash the desired lights by column (there are 6 columns) so that my light time is 1/6 of the allotted time per light, not the 1/30th if I were to do them individually
-
So I'm currently working to make a way to code the outputs as 1 and inputs as 0, so that I can add them using bitwise operations. I'm also seeing if I can do this in array, or if I need to make a reference to what they are out of array (I think this is what I'll have to do)
-
For whatever reason it won't let me classify row "F" as "F", as it doesn't recognize it. hence I labeled it "G". Anyone have any pointers on this?
Here's my Circuit
I borrowed this picture from online, it's not mine, but everything is the same
Here's my Code
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define G 7
#define PIN_CONFIG 0
#define PIN_STATE 1
#define LED_COUNT 6
int matrix[LED_COUNT][5][6] = {
// PIN_CONFIG (Horizontal) PIN_STATE (Vertical)
// A B C D E G A, B, C, D, E, G
/*
// Values by column taking out 1 led
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT}, { 1, 0, 0, 0, 0, 0} }, // A !1
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT}, { 1, 0, 0, 0, 0, 0} }, // A !2
{ { OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT}, { 1, 0, 0, 0, 0, 0} }, // A !3
{ { OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT}, { 1, 0, 0, 0, 0, 0} }, // A !4
{ { OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 1, 0, 0, 0, 0, 0} }, // A !5
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT}, { 0, 1, 0, 0, 0, 0} }, // B !1
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT}, { 0, 1, 0, 0, 0, 0} }, // B !2
{ { OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT}, { 0, 1, 0, 0, 0, 0} }, // B !3
{ { OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 1, 0, 0, 0, 0} }, // B !4
{ { INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 1, 0, 0, 0, 0} }, // B !5
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT}, { 0, 0, 1, 0, 0, 0} }, // C !1
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT}, { 0, 0, 1, 0, 0, 0} }, // C !2
{ { OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT}, { 0, 0, 1, 0, 0, 0} }, // C !3
{ { OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 1, 0, 0, 0} }, // C !4
{ { INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 1, 0, 0, 0} }, // C !5
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT}, { 0, 0, 0, 1, 0, 0} }, // D !1
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT}, { 0, 0, 0, 1, 0, 0} }, // D !2
{ { OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 1, 0, 0} }, // D !3
{ { OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 1, 0, 0} }, // D !4
{ { INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 1, 0, 0} }, // D !5
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT}, { 0, 0, 0, 0, 1, 0} }, // E !1
{ { OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 1, 0} }, // E !2
{ { OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 1, 0} }, // E !3
{ { OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 1, 0} }, // E !4
{ { INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 1, 0} }, // E !5
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G !1
{ { OUTPUT, OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G !2
{ { OUTPUT, OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G !3
{ { OUTPUT, INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G !4
{ { INPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G !5
*/
// Values by column
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 1, 0, 0, 0, 0, 0} }, // A
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 1, 0, 0, 0, 0} }, // B
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 1, 0, 0, 0} }, // C
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 1, 0, 0} }, // D
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 1, 0} }, // E
{ { OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G
/*
// Values of each light individually
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT}, { 1, 0, 0, 0, 0, 0} }, // A1
{ { OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT}, { 1, 0, 0, 0, 0, 0} }, // A2
{ { OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT}, { 1, 0, 0, 0, 0, 0} }, // A3
{ { OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT}, { 1, 0, 0, 0, 0, 0} }, // A4
{ { OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT}, { 1, 0, 0, 0, 0, 0} }, // A5
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT}, { 0, 1, 0, 0, 0, 0} }, // B1
{ { INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT}, { 0, 1, 0, 0, 0, 0} }, // B2
{ { INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT}, { 0, 1, 0, 0, 0, 0} }, // B3
{ { INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT}, { 0, 1, 0, 0, 0, 0} }, // B4
{ { OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT}, { 0, 1, 0, 0, 0, 0} }, // B5
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT}, { 0, 0, 1, 0, 0, 0} }, // C1
{ { INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT}, { 0, 0, 1, 0, 0, 0} }, // C2
{ { INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT}, { 0, 0, 1, 0, 0, 0} }, // C3
{ { INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT}, { 0, 0, 1, 0, 0, 0} }, // C4
{ { OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT}, { 0, 0, 1, 0, 0, 0} }, // C5
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT}, { 0, 0, 0, 1, 0, 0} }, // D1
{ { INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT}, { 0, 0, 0, 1, 0, 0} }, // D2
{ { INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT}, { 0, 0, 0, 1, 0, 0} }, // D3
{ { INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT}, { 0, 0, 0, 1, 0, 0} }, // D4
{ { OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT}, { 0, 0, 0, 1, 0, 0} }, // D5
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 1, 0} }, // E1
{ { INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT}, { 0, 0, 0, 0, 1, 0} }, // E2
{ { INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT}, { 0, 0, 0, 0, 1, 0} }, // E3
{ { INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT}, { 0, 0, 0, 0, 1, 0} }, // E4
{ { OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT}, { 0, 0, 0, 0, 1, 0} }, // E5
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G1
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G2
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G3
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G4
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT}, { 0, 0, 0, 0, 0, 1} }, // G5
*/
};
void turnOn( int led ) {
pinMode( A, matrix[led][PIN_CONFIG][0] );
pinMode( B, matrix[led][PIN_CONFIG][1] );
pinMode( C, matrix[led][PIN_CONFIG][2] );
pinMode( D, matrix[led][PIN_CONFIG][3] );
pinMode( E, matrix[led][PIN_CONFIG][4] );
pinMode( G, matrix[led][PIN_CONFIG][5] );
digitalWrite( A, matrix[led][PIN_STATE][0] );
digitalWrite( B, matrix[led][PIN_STATE][1] );
digitalWrite( C, matrix[led][PIN_STATE][2] );
digitalWrite( D, matrix[led][PIN_STATE][3] );
digitalWrite( E, matrix[led][PIN_STATE][4] );
digitalWrite( G, matrix[led][PIN_STATE][5] );
}
void setup() {}
void loop() {
for( int l = 0; l < LED_COUNT; l++ ) {
turnOn( l );
delay( 30 / LED_COUNT );
}
}