Charlieplexing 20LED test
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
| // 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