Skip to content

Instantly share code, notes, and snippets.

@lpereira
Created October 29, 2011 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lpereira/1324915 to your computer and use it in GitHub Desktop.
Save lpereira/1324915 to your computer and use it in GitHub Desktop.
Arduino Charlieplexing
static const byte charlie_pins[] = {5, 6, 7};
static const byte charlie_led[][2] = {
{ 0, 1 },
{ 1, 0 },
{ 0, 2 },
{ 2, 0 },
{ 1, 2 },
{ 2, 1 }
};
void charlie(int n_led, boolean state)
{
byte *led = charlie_led[n_led];
byte vcc = led[0], gnd = led[1];
byte z = charlie_pins[(byte[]){2, 0, 1, 0}[(1 << vcc | 1 << gnd) - 3]];
vcc = charlie_pins[vcc];
gnd = charlie_pins[gnd];
pinMode(vcc, OUTPUT);
pinMode(gnd, OUTPUT);
pinMode(z, INPUT);
digitalWrite(gnd, LOW);
digitalWrite(vcc, state);
}
void setup()
{
for (int i = 0; i < 6; i++)
charlie(i, false);
}
void loop() {
static byte state = 0, led = 0, blinks = 0;
if (++blinks > 10) {
blinks = 0;
if (++led > 5)
led = 0;
}
charlie(led, state);
state ^= 1;
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment