Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
Based on https://github.com/maltesemanTS1/Charlieplexing-the-Arduino
http://arduino.cc/en/Tutorial/BitMask
*/
const int LED_A = 21; //LED row 1
const int LED_B = 20; //LED row 2
const int LED_C = 19; //LED row 3
const int LED_D = 18; //LED row 1
const int LED_E = 17; //LED row 2
const int LED_F = 16; //LED row 3
boolean picture[30] = {
0,1,0,
1,0,1,
0,1,0,
1,0,1,
0,1,0,
1,0,1,
0,1,0,
1,0,1,
0,1,0,
1,0,1,
};
const int frames = 5;
boolean animation_arr[frames][30] = {
{
1,1,0,
1,0,1,
1,0,1,
1,0,1,
1,1,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
},
{
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,1,0,
1,0,1,
1,1,1,
1,0,1,
1,0,1,
},
{
1,0,1,
1,0,1,
1,0,1,
1,0,1,
0,1,0,
1,0,1,
1,0,1,
1,0,1,
1,0,1,
0,1,0,
},
{
1,1,1,
1,0,0,
1,1,1,
1,0,0,
1,1,1,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
},
{
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
0,0,0,
}
};
void setup() {
Serial.begin(9600);
}
void loop() {
for (int k=0; k<frames; k++) {
for (int j=0; j<64; j++) {
for (int i=0; i<30; i++) {
if (animation_arr[k][i]) charlie(i);
else charlie(-1);
}
}
}
}
void show_picture () {
for (int j=0; j<127; j++) {
for (int i=0; i<30; i++) {
if (picture[i]) charlie(i);
}
}
}
void gogo () {
for (int j=0; j<127; j++) {
for (int i=0; i<15; i++) {
charlie(i);
}
}
for (int j=0; j<127; j++) {
for (int i=15; i<31; i++) {
charlie(i);
}
}
for (int j=0; j<64; j++) {
for (int i=0; i<31; i++) {
charlie(i);
}
}
}
void charlie (int var) {
pinMode(LED_A, INPUT);
digitalWrite(LED_A, LOW);
pinMode(LED_B, INPUT);
digitalWrite(LED_B, LOW);
pinMode(LED_C, INPUT);
digitalWrite(LED_C, LOW);
pinMode(LED_D, INPUT);
digitalWrite(LED_D, LOW);
pinMode(LED_E, INPUT);
digitalWrite(LED_E, LOW);
pinMode(LED_F, INPUT);
digitalWrite(LED_F, LOW);
switch (var) {
case 0:
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, HIGH);
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, LOW);
break;
case 1:
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, HIGH);
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, LOW);
break;
case 2:
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, HIGH);
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, LOW);
break;
//
case 3:
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, HIGH);
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, LOW);
break;
case 4:
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, HIGH);
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, LOW);
break;
case 5:
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, HIGH);
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, LOW);
break;
//
case 6:
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, HIGH);
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, LOW);
break;
case 7:
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, HIGH);
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, LOW);
break;
case 8:
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, HIGH);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, LOW);
break;
//
case 9:
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, HIGH);
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, LOW);
break;
case 10:
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, HIGH);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, LOW);
break;
case 11:
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, HIGH);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, LOW);
break;
//
case 12:
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, HIGH);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, LOW);
break;
case 13:
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, HIGH);
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, LOW);
break;
case 14:
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, HIGH);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, LOW);
break;
//
case 15:
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, LOW);
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, HIGH);
break;
case 16:
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, LOW);
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, HIGH);
break;
case 17:
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, LOW);
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, HIGH);
break;
//
case 18:
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, LOW);
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, HIGH);
break;
case 19:
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, LOW);
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, HIGH);
break;
case 20:
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, LOW);
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, HIGH);
break;
//
case 21:
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, LOW);
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, HIGH);
break;
case 22:
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, LOW);
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, HIGH);
break;
case 23:
pinMode(LED_C, OUTPUT);
digitalWrite(LED_C, LOW);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, HIGH);
break;
//
case 24:
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, LOW);
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, HIGH);
break;
case 25:
pinMode(LED_D, OUTPUT);
digitalWrite(LED_D, LOW);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, HIGH);
break;
case 26:
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, LOW);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, HIGH);
break;
//
case 27:
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, LOW);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, HIGH);
break;
case 28:
pinMode(LED_E, OUTPUT);
digitalWrite(LED_E, LOW);
pinMode(LED_A, OUTPUT);
digitalWrite(LED_A, HIGH);
break;
case 29:
pinMode(LED_B, OUTPUT);
digitalWrite(LED_B, LOW);
pinMode(LED_F, OUTPUT);
digitalWrite(LED_F, HIGH);
break;
//
default:
;
}
delayMicroseconds(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.