Created
January 7, 2014 02:36
-
-
Save jefflarkin/8293839 to your computer and use it in GitHub Desktop.
Example of using Charlieplexing [http://en.wikipedia.org/wiki/Charlieplexing] to control 6 LEDs with an arduino.
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 6 LEDs with Arduino Uno **/ | |
/** Jeff Larkin [http://github.com/jefflarkin] **/ | |
/* | |
* Wiring Diagram: | |
* | |
* pin 2 ===== led0+, led1- ===== led4+, led5- | |
* pin 4 ===== led1+, led0- ===== led2+, led3- | |
* pin 6 ===== led3+, led2- ===== led5+, led4- | |
* | |
*/ | |
int pins[] = {2,4,6}; | |
void setup() | |
{ | |
for (int i = 0; i < 3; i++) | |
{ | |
pinMode(pins[i],INPUT); | |
} | |
} | |
void loop() | |
{ | |
for(int i = 0; i < 6; i++) | |
{ | |
lightLED(i); | |
delay(250); | |
} | |
} | |
void lightLED(int i) | |
{ | |
switch(i) | |
{ | |
case 0: | |
pinMode(pins[0],OUTPUT); | |
pinMode(pins[1],OUTPUT); | |
pinMode(pins[2],INPUT); | |
digitalWrite(pins[0],HIGH); | |
digitalWrite(pins[1],LOW); | |
break; | |
case 1: | |
pinMode(pins[0],OUTPUT); | |
pinMode(pins[1],OUTPUT); | |
pinMode(pins[2],INPUT); | |
digitalWrite(pins[1],HIGH); | |
digitalWrite(pins[0],LOW); | |
break; | |
case 2: | |
pinMode(pins[0],INPUT); | |
pinMode(pins[1],OUTPUT); | |
pinMode(pins[2],OUTPUT); | |
digitalWrite(pins[1],HIGH); | |
digitalWrite(pins[2],LOW); | |
break; | |
case 3: | |
pinMode(pins[0],INPUT); | |
pinMode(pins[1],OUTPUT); | |
pinMode(pins[2],OUTPUT); | |
digitalWrite(pins[1],LOW); | |
digitalWrite(pins[2],HIGH); | |
break; | |
case 4: | |
pinMode(pins[0],OUTPUT); | |
pinMode(pins[1],INPUT); | |
pinMode(pins[2],OUTPUT); | |
digitalWrite(pins[0],HIGH); | |
digitalWrite(pins[2],LOW); | |
break; | |
case 5: | |
pinMode(pins[0],OUTPUT); | |
pinMode(pins[1],INPUT); | |
pinMode(pins[2],OUTPUT); | |
digitalWrite(pins[0],LOW); | |
digitalWrite(pins[2],HIGH); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment