Skip to content

Instantly share code, notes, and snippets.

@houmei
Created March 19, 2015 13:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Charlieplexing 20LED test
// Charlieplexing
// 20150319 @houmei
//
#define MAXCharlie 5
int Charlie[] = { 12,11,10,9,8 };
int CA[] = {
0,1, 0,2, 0,3, 0,4, 1,2, 1,3, 1,4, 2,3, 2,4, 3,4
};
int CB[] = {
1,0, 2,0, 3,0, 4,0, 2,1, 3,1, 4,1, 3,2, 4,2, 4,3
};
void setup() {
all_off();
}
int pos = 0;
int dir = 1;
void loop() {
all_off();
turn_on(pos);
pos = pos + dir;
if (pos>=20) {
pos=19;
dir = -1;
}
if (pos<0) {
pos=0;
dir = 1;
}
delay(30);
}
void all_off() {
for(int i=0; i<MAXCharlie; i++) {
pinMode(Charlie[i],INPUT);
}
}
void turn_on(int num) {
int pA,pB,xA,xB;
if (num>=0 && num <20) {
xA = CA[num]; xB = CB[num]; // get Chari¥lieplex Index
pA = Charlie[xA] ; pB = Charlie[xB]; // get Charlieplex port No.
pinMode(pA,OUTPUT);
pinMode(pB,OUTPUT);
digitalWrite(pA,LOW);
digitalWrite(pB,HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment