Hi All,
I have acquired some code online regarding Charlieplexing as i need around 70 LEDs for a project I'm working on. At any one time, 30-35 are likely to be lit. Then a switch is thrown and the one LED turns off and another turns on.
When running the program, (16 are connected so far) the LED lights individually and it cycles through, lighting one after the other, then restarts - as the program is supposed to. However, when I type
lightOn( 0 );
It lights the first LED correctly, however, if I type
lightOn( 1 );
It starts being odd with the lights.
If I ask it to turn on lights 0 and 2 it will light 0, 1 and 2, but 1 and 2 are dimmer.
I'm a bit confused with it to be honest, and I'm definitely no expert. Does anyone have any advice?
#define G 45 // We call pin #46 A
#define H 46 // " " " #47 B
#define I 47 // " " " #48 C
#define J 48 // " " " #49 D
#define K 49
#define L 50
#define M 51
#define N 52
#define O 53
#define PIN_CONFIG 0 // Setup our Boolean config for the 9 pins
#define PIN_STATE 1 // Setup our Boolean state for the 9 pins
#define LED_Num 72 // How many LEDs are we using
int matrix[LED_Num][2][9] = {
// PIN_CONFIG PIN_STATE
// G H I J K L M N O G H I J K L M N O
{ { OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //1
{ { OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //2
{ { INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //3
{ { INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW } }, //4
{ { INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW } }, //5
{ { INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW } }, //6
{ { INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW } }, //7
{ { INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW } }, //8
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW } }, //9
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW } }, //10
{ { INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW } }, //11
{ { INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW } }, //12
{ { INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW } }, //13
{ { INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW } }, //14
{ { INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW } }, //15
{ { INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH } }, //16
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH } }, //17
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT }, { HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //18
{ { OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //19
{ { OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW } }, //20
{ { OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //22
{ { OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW } }, //23
{ { OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT }, { HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //24
{ { OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW } }, //25
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT }, { HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //26
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW } }, //27
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT }, { HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //28
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW } }, //29
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT }, { HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //30
{ { OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW } }, //31
{ { INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //32
{ { INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW } }, //33
{ { INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //34
{ { INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW } }, //35
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT }, { LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //36
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW } }, //37
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT }, { LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //38
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW } }, //39
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT }, { LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //40
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW } }, //41
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT }, { LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW } }, //42
{ { INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH } }, //43
{ { INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW } }, //44
{ { INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW } }, //45
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT }, { LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW } }, //46
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW } }, //47
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW } }, //48
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW } }, //49
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW } }, //50
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW } }, //51
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW } }, //52
{ { INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH } }, //53
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW } }, //54
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW } }, //55
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW } }, //56
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW } }, //57
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW } }, //58
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW } }, //59
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW } }, //60
{ { INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH } }, //61
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW } }, //62
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW } }, //63
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW } }, //64
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW } }, //65
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW } }, //66
{ { INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH } }, //67
{ { INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW } }, //68
{ { INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT, INPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW } }, //69
{ { INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW } }, //69
{ { INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH } }, //70
{ { INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW } }, //71
{ { INPUT, INPUT, INPUT, INPUT, INPUT, INPUT, OUTPUT, INPUT, OUTPUT }, { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH } } //72
};
void
lightOn( int led ) {
pinMode( G, matrix[led][PIN_CONFIG][0] );
pinMode( H, matrix[led][PIN_CONFIG][1] );
pinMode( I, matrix[led][PIN_CONFIG][2] );
pinMode( J, matrix[led][PIN_CONFIG][3] );
pinMode( K, matrix[led][PIN_CONFIG][4] );
pinMode( L, matrix[led][PIN_CONFIG][5] );
pinMode( M, matrix[led][PIN_CONFIG][6] );
pinMode( N, matrix[led][PIN_CONFIG][7] );
pinMode( O, matrix[led][PIN_CONFIG][8] );
digitalWrite( G, matrix[led][PIN_STATE][0] );
digitalWrite( H, matrix[led][PIN_STATE][1] );
digitalWrite( I, matrix[led][PIN_STATE][2] );
digitalWrite( J, matrix[led][PIN_STATE][3] );
digitalWrite( K, matrix[led][PIN_STATE][4] );
digitalWrite( L, matrix[led][PIN_STATE][5] );
digitalWrite( M, matrix[led][PIN_STATE][6] );
digitalWrite( N, matrix[led][PIN_STATE][7] );
digitalWrite( O, matrix[led][PIN_STATE][8] );
}
void setup() {
Serial.begin(9600);
}
void loop() {
for ( int l = 0; l < LED_Num; l++ ) {
lightOn( l );
delay( 20000 / LED_Num );
}
}