Optimized Arduino/AVR Charlieplexing Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define A 12 | |
#define B 11 | |
#define C 10 | |
#define D 9 | |
#define LED_COUNT 12 | |
#define DDR_BYTE 0 | |
#define PORT_BYTE 1 | |
byte matrix[LED_COUNT][2] = { | |
// DDR_BYTE PORT_BYTE | |
// ABCD ABCD | |
{ 0b00011000, 0b00010000 }, // AB 0 | |
{ 0b00011000, 0b00001000 }, // BA 1 | |
{ 0b00001100, 0b00001000 }, // BC 2 | |
{ 0b00001100, 0b00000100 }, // CB 3 | |
{ 0b00010100, 0b00010000 }, // AC 4 | |
{ 0b00010100, 0b00000100 }, // CA 5 | |
{ 0b00010010, 0b00010000 }, // AD 6 | |
{ 0b00010010, 0b00000010 }, // DA 7 | |
{ 0b00001010, 0b00001000 }, // BD 8 | |
{ 0b00001010, 0b00000010 }, // DB 9 | |
{ 0b00000110, 0b00000100 }, // CD 10 | |
{ 0b00000110, 0b00000010 } // DC 11 | |
}; | |
void turnOn( byte led ) { | |
DDRB = matrix[led][DDR_BYTE]; | |
PORTB = matrix[led][PORT_BYTE]; | |
} | |
void setup() {} | |
void loop() { | |
for( byte l = 0; l < LED_COUNT; l++ ) { | |
turnOn( l ); | |
delay( 10 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment