Created
          October 29, 2011 18:41 
        
      - 
      
- 
        Save lpereira/1324915 to your computer and use it in GitHub Desktop. 
    Arduino Charlieplexing
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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