can anybody help increase this to a 5 pin or more and how to alter the wiring to match I have been at this for hours and now am struggling
(wood and the trees syndrome)
After 17 posts I would expect you to know about code tags... So please edit your post and add code tags.
And just this morning I wrote this post. With the excel sheet (and if you know how Charlieplexing works) it should not be to hard to edit the code for 5 pin aka 20 leds.
Once you have done that, i can tell you about a different way to think about charlieplexing, which makes drawing the schematics and writing the code much easier (and shorter), for any number of pins.
So, this is the way I think about charlieplexing. To me its much easier.
Lets take your 3 pin example and draw a different diagram.
Imagine wires extending out in parallel from the 3 Arduino pins, via the 3 series resistors. Put the 6 leds in a line above them. Because there are 3 pins, group the leds into 3 groups. Each group therefore has 2 leds.
Next, common-up the anodes in each group. Attach each common anode to one of the 3 wires.
Then wire up the cathodes. The cathodes in each group should connect to the lines not already used to connect the anode of that group. As you go left to right in each group, use the wires top to bottom, in a methodical pattern.
still following you am going to get pen and paper and try with more leds and lines to see if I understand will post on here so you can have a look and tell me if I am getting there or am way of
Mm, cool work Paul. I tried some sort of algorithm myself but couldn't find one. But now I look at it i see a flaw... This is the truth table I get from you're algorithm:
0 1 2
0 p n
1 p n
2 n p
3 p n
4 n p
5 n p
i = 0 and i = 1 will do the same...
But the code really helped me making the real algorithm! (aka, spot the error)
if (member == group) {
//should be
if (member >= group) {
My total code: (don't like to define a number that the compiler already knows...)
//Pins that drive the charlieplexing
const byte Pins[] = {5, 6, 7};
//turns on a specific led of the charlieplex
void turnOnLed(byte nr){
//do nothing if the number is to high
if(nr >= numberOfLeds() ){
return;
}
//calculate the group (positive end) and member (negative end)
byte group = nr / (sizeof(Pins) - 1);
byte member = nr % (sizeof(Pins) - 1);
//Here is the fix :D
//correct for itself not counting
if (member >= group) {
member++;
}
//Set each pin corresponding
for(byte i = 0; i < sizeof(Pins); i++){
if(i == group){
pinMode(Pins[i], OUTPUT);
digitalWrite(Pins[i], HIGH);
}
else if(i == member){
pinMode(Pins[i], OUTPUT);
digitalWrite(Pins[i], LOW);
}
else{
pinMode(Pins[i], INPUT);
}
}
}
//returns the number of leds based on the number of pins
inline byte numberOfLeds(){
return sizeof(Pins) * (sizeof(Pins) - 1);
}
To test the algorithm I make a spreadsheet. That's what made the truth table. I added this to the first lookup table spreadsheet I made. Here is the Google Sheet.
Why? If the LED are all the same (aka, need the same resistor) you can just do it like that and use resistors that are halve of what you need. At all times you have two resistors in series with the led
thanks Paul you made it easier for me,
5 pins equals 4 leds so if I want 10 leds I need 11 pins looks like a arduino mega is needed
but once again thanks for your help