My Arduino doesn't have 40(15+21+3) outputs and 3 inputs, so I either need to drop features (Which doesn't sound like the fun thing to do), buy an Arduino Mega (Where's the fun in that) or I need to find a clever way to make it work. While I'm usually lazy, doing the impossible sounds like a lot more fun (Ok, the improbable then...)
I've already managed to hook 5 buttons to one analog input and documented that here:
http://www.instructables.com/id/How-to-access-5-buttons-through-1-Arduino-input/
By using Charlieplexing, you can hook up n*(n-1) LED's to n microcontroller pins. I'll go through the theory in the next step, but from this you can see that I can hook up 20 LED's on 5 pins or 12 LED's on 4 pins, which would be a great start for actually making this all work on 1 Arduino.
If you search Instructables (and Google for that matter), You'll find lots of theoretical explanations of how Charlieplexing work, and you'll even find some examples of Charlieplexed LED's running on Arduino's. The problem is that the code on these examples are generally not explained very well, and are usually very tightly tied to the exact hardware setup that the author used. This makes it an exercise in futility and frustration to try and make it work on your own projects.
I will show you exactly how this works, how to set it up with as many LED's as you would like in as painless a manner as possible (Although it gets horribly complicated if you go to more than about 30 LED's), how to code it so it works for you, and which problems I had to overcome in the process.
Remove these ads by
Signing UpStep 1The parts list
5 Resistors - I used 100 Ohm resistors (Brown Black Brown). The value depends on your resistors, but will probably be somewhere between about 75 and 150 Ohm. If the value is too big, your LED's will be dim. If they are too small, more than one LED will turn on at the same time.
An Arduino. This is the brains of the project. Well, actually, I'm the brains, but you get the idea... I'm using a Diecimila for this project.
Some wire to hook it all together (Actually, LOTS of wire).
| « Previous Step | Download PDFView All Steps | Next Step » |










































I'm new to coding and it would REALLY help.
Please :-}
To make things easier for me when I set up my Charileplexed matrix I did it exactly as you see the first image.
Into a piece of wood I drilled two sets of five holes about 5 inches apart. Then I strung wire between those holes and soldered the LEDs across them as you showed in the first example. I soldered resistors to the end of the wires. I checked the matrix by running power across each wire. The LEDs lit up correctly and worked fine. Then I plugged them into pins 1, 2 , 3 ,4 and 5.
However when I loaded your program, which I have to admit I have trouble following, nothing happened... Where did I go wrong?
The second problem you have is that the pins in the software doesn't correspond to the way you've wired them up to the Arduino. This is a bit confusing, and I don't specifically mention it... I'll fix that in the Instrucatable.
If you look at the code, you'll see this at the top:
#define A 8
#define B 9
#define C 10
#define D 11
#define E 12
That defines what pins connect the Arduino to the Charlieplex. So just change your connections to connect to pins 8-12 and it should work fine.
http://www.youtube.com/watch?v=YBJwUTHt8Do
I had to change this part:
int c[5][4][2] =
{
{ {A, B}, {A, C}, {A, D}, {A, E} },
{ {B, A}, {B, C}, {B, D}, {B, E} },
{ {C, A}, {C, B}, {C, D}, {C, E} },
{ {D, A}, {D, B}, {D, C}, {D, E} },
{ {E, A}, {E, B}, {E, C}, {E, D} }
};
To this:
{
{ {A, B}, {B, A}, {B, C}, {C, B} },
{ {C, D}, {D, C}, {D, E}, {E, D} },
{ {A, C}, {C, A}, {B, D}, {D, B} },
{ {C, E}, {E, C}, {A, D}, {D, A} },
{ {B, E}, {E, B}, {A, E}, {E, A} }
}
So that my LEDs would light in order.
I know this may be asking a bit much but if I wanted to create different patterns instead of just cycling through each LED what might be the best way?
The 'int frames[][5] = {..}' array defines the patterns to display, and you can display the pattern using the 'void display( int frame[5], int duration ){...}' method.
Below is the first "frame" of animation code that would start out in the middle of a strip of 20 charlieplexed LEDs then go out to both ends and back into the middle again.
int ledPin1 = 8;
int ledPin2 = 9;
int ledPin3 = 10;
int ledPin4 = 11;
int ledPin5 = 12;
void setup() {
}
void loop() {
int a;
for( a = 0; a < 50; a++ )
{
pinMode(ledPin1, INPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, INPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, INPUT);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin4, LOW);
delay(.5);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, INPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, INPUT);
pinMode(ledPin5, INPUT);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin1, LOW);
delay(.5);
}
Now I just have to figure out how to add a potentiometer to vary the speed of the animation and either a rotary switch or a series of switches that would enable me to change to the different patterns...
Thanks for the head start. :-)