20 LEDs all ina row... Charlieplexing style! How to address each??

I don't know how to address each led. C++ and I are not friends. No idea.
I try to scrap bits and pieces of code.

They run now.. but not in an order I understand.

charlieMatrix3.ino (554 Bytes)

Followed this picture...

Ok, dig this, by why do they go out of order on my breadboard? I wired just 20leds to 5pins. It blinks: 1 2 9 10 15 16 19 20 3 4 11 12 17 18 5 6 13 14 7 8

And how do I address them individually??

It's a jungle in there baby

20 LEDs in a row? Why do you want to charlieplex them at all? The Arduino can handle 20 LEDs without any tricks. See my webpage dedicated to 20 LEDs in a row :wink:

You asked this in this thread: http://arduino.cc/forum/index.php/topic,112711.0.html. Do you still want help with it, or did you work it out?

I didn't get any help in he 100led one... did I ? If so I missed it an apologize. Sorry.

If no reply there then I still need help.

Oh and want to charlieplex for wire management. Only need to get 5 wires to the site from batteries/arduino location.

This was the best reply:

You have them wired like this:

---2--- ---3--- ---4--- ---5--- ---2--- ---3--- ---4--- ---2--- ---3--- ---2--- PIN#
-- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 LED#
/ -- / -- / -- / -- / -- / -- / -- / -- / -- / --
---3--- ---4--- ---5--- ---6--- ---4--- ---5--- ---6--- ---5--- ---6--- ---6--- PIN#

That looks a lot like the schamtic previously posted in this thread. And, that's a handy way of making a schematic, but it's certainly not the only way to wire the LEDs. When you charlieplex, you have to match your code to your wiring.

Here's the arrangement that I had in mind:

---2--- ---2--- ---2--- ---2--- ---3--- ---3--- ---3--- ---4--- ---4--- ---5--- PIN#
-- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 LED#
/ -- / -- / -- / -- / -- / -- / -- / -- / -- / --
---3--- ---4--- ---5--- ---6--- ---4--- ---5--- ---6--- ---5--- ---6--- ---6--- PIN#

Notice that it looks a lot like the code: the upper pins are the slowly-varying index, and the lower pins are the rapidly-varying index.

There's a straightforward solution that doesn't involve rewiring. Define an array, NLEDS x 2, that holds the LOW pin and the HIGH pin for each pair of LEDs. To light one, get its pins, and manipulate the outputs to light it up. A code snippet might be:
Code:

for (uint8_t i=2;i<=NLEDS;i++) {
pinMode(LEDArray*[0],OUTPUT);*
_ pinMode(LEDArray*[1],OUTPUT);_
_ digitalWrite(LEDArray[0],HIGH);
delay();
digitalWrite(LEDArray[0],LOW);
digitalWrite(LEDArray[1],HIGH);
delay();
pinMode(LEDArray[0],INPUT);
pinMode(LEDArray[1],INPUT);
...
If you don't get the array right the first time, trial and error will get the answer. For your wiring, this might be the array:
{2,3},{3,4},{4,5},{5,6},{2,4},{3,5},{4,6},{2,5},{3,6},{2,6}*_

BTW:

Thanks tmd3 USA!!

Guess I need to learn some C++ just a little more. Will try to figure out that snippet of code today.

Not sure if I can wrap my head around the rewire.

Oh, i think I get it, the referencing points are the two pins from upper and lower connectors. So it is just 2,3 to turn on 1 and 3,2 for 2? Wait, so 2 high 3 low for 1. And 3 high and 2 low for 2? Sweet, if that is it

MasterErik:
This was the best reply:

You have them wired like this:

---2--- ---3--- ---4--- ---5--- ---2--- ---3--- ---4--- ---2--- ---3--- ---2--- PIN#
-- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 LED#
/ -- / -- / -- / -- / -- / -- / -- / -- / -- / --
---3--- ---4--- ---5--- ---6--- ---4--- ---5--- ---6--- ---5--- ---6--- ---6--- PIN#

That looks a lot like the schamtic previously posted in this thread. And, that's a handy way of making a schematic, but it's certainly not the only way to wire the LEDs. When you charlieplex, you have to match your code to your wiring.

Here's the arrangement that I had in mind:

---2--- ---2--- ---2--- ---2--- ---3--- ---3--- ---3--- ---4--- ---4--- ---5--- PIN#
-- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /\ -- /
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 LED#
/ -- / -- / -- / -- / -- / -- / -- / -- / -- / --
---3--- ---4--- ---5--- ---6--- ---4--- ---5--- ---6--- ---5--- ---6--- ---6--- PIN#

Notice that it looks a lot like the code: the upper pins are the slowly-varying index, and the lower pins are the rapidly-varying index.

There's a straightforward solution that doesn't involve rewiring. Define an array, NLEDS x 2, that holds the LOW pin and the HIGH pin for each pair of LEDs. To light one, get its pins, and manipulate the outputs to light it up. A code snippet might be:
Code:

for (uint8_t i=2;i<=NLEDS;i++) {
pinMode(LEDArray*[0],OUTPUT);*
_ pinMode(LEDArray*[1],OUTPUT);_
_ digitalWrite(LEDArray[0],HIGH);
delay();
digitalWrite(LEDArray[0],LOW);
digitalWrite(LEDArray[1],HIGH);
delay();
pinMode(LEDArray[0],INPUT);
pinMode(LEDArray[1],INPUT);
...
If you don't get the array right the first time, trial and error will get the answer. For your wiring, this might be the array:
{2,3},{3,4},{4,5},{5,6},{2,4},{3,5},{4,6},{2,5},{3,6},{2,6}
[/quote]*_

I have this code:

int NLEDS[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
int LEDArray = sizeof(NLEDS)/sizeof(int);

void loop(){

for (uint8_t i=2;i<=NLEDS;i++) {
pinMode(LEDArray*[0],OUTPUT);*
_ pinMode(LEDArray*[1],OUTPUT);_
_ digitalWrite(LEDArray[0],HIGH);
delay(300);
digitalWrite(LEDArray[0],LOW);
digitalWrite(LEDArray[1],HIGH);
delay(300);
pinMode(LEDArray[0],INPUT);
pinMode(LEDArray[1],INPUT);*_

}
----- But it doesn't work and I don't understand how that can address each one.

Uhg.
Think I need a break from this.

charlieMatrix4.cpp: In function 'void loop()':
charlieMatrix4:5: error: ISO C++ forbids comparison between pointer and integer
charlieMatrix4:6: error: invalid types 'int[uint8_t]' for array subscript
charlieMatrix4:7: error: invalid types 'int[uint8_t]' for array subscript
charlieMatrix4:8: error: invalid types 'int[uint8_t]' for array subscript
charlieMatrix4:10: error: invalid types 'int[uint8_t]' for array subscript
charlieMatrix4:11: error: invalid types 'int[uint8_t]' for array subscript
charlieMatrix4:13: error: invalid types 'int[uint8_t]' for array subscript
charlieMatrix4:14: error: invalid types 'int[uint8_t]' for array subscript
charlieMatrix4:16: error: expected `}' at end of input

Would it be easier to just rewire? It is just on a breadboard. Was hoping to understand code. Not sure how to go about understanding the code.

Might just rewire, I like hardware.

But if I just rewire... how does the code address each led?
Does it start at 2 and 6 and increment both equally one at a time?

void setup() {
for (uint8_t i=2;i<=6;i++) {
pinMode(i,INPUT);
digitalWrite(i,LOW);
}
}

void loop() {
uint8_t n = 0;
for (uint8_t i=2;i<=6;i++) {
pinMode(i,OUTPUT);
for (uint8_t j=i+1;j<=6;j++) {
pinMode(j,OUTPUT);
digitalWrite(i,HIGH);
delay(500);
n++;
digitalWrite(i,LOW);
digitalWrite(j,HIGH);
delay(500);
digitalWrite(j,LOW);
n++;
pinMode(j,INPUT);
if (n == 20) {
break;
}
}
pinMode(i,INPUT);
if (n == 20) {
break;
}
}
}

First, some housekeeping: Look back at the code you've posted. I'm not sure what you see, but I see unusual characters replacing important code bits. The forum's software is interpreting some of the characters as special codes that tell it to display strange stuff. Avoid this by putting your code in code tags - use the "#" button.

And 3 high and 2 low for 2? Sweet, if that is it.

I thought you had it there.

Would it be easier to just rewire?

Your call. Do you just want to make this one work, or do you want to learn how to make this kind of stuff work?

... how does the code address each led? Does it start at 2 and 6 and increment both equally one at a time?

No. Work your way through it: i starts at 2, j starts at i+1 = 3; then j goes to 4, then 5, then 6. i goes to 3; j starts at 4, goes to 5, then 6. And so on. Looks like you're not entirely clear on how a loop works.

int NLEDS[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
int LEDArray = sizeof(NLEDS)/sizeof(int);

I'm baffled by this. The array is nothing but a sequential list of indexes, and those indexes are really nothing more than the names you gave the LEDs - they're not connected to anything in the circuiting. The int is just 20, but you don't learn anything from it - you already told NLEDS to be 20 elements in size.

digitalWrite(LEDArray[1],HIGH);Here's what's wrong with this: LEDArray is an int, not an array. I'm thinking that this code didn't compile - is that right?

How would you like to proceed? We can post code that will give you the result you want, or we can help you work through it. My instincts say that you're unfamiliar with C, and with programming in general. Maybe we'd serve you best by getting this one working, and letting you get on with learning the language; maybe you'd prefer to work through this as a learning experience. How would you like to proceed?

Place a # before and after? I don't see and unusual characters but will add # around my code.

tmd3:
First, some housekeeping: Look back at the code you've posted. I'm not sure what you see, but I see unusual characters replacing important code bits. The forum's software is interpreting some of the characters as special codes that tell it to display strange stuff. Avoid this by putting your code in code tags - use the "#" button.

I can see how the numbers given can access the leds separately but don't know how to tell it those numbers with out it not working/verifying.

And 3 high and 2 low for 2? Sweet, if that is it.

I thought you had it there.

Would like to make it work and want to figure it out. Telling me how i and j move was helpful!

Would it be easier to just rewire?

Your call. Do you just want to make this one work, or do you want to learn how to make this kind of stuff work?

Not sure on loop, but seeing it put like this helps. Will go stare at it some more and see if I can increment or tell it individually. Trying to figure out how to write it.

... how does the code address each led? Does it start at 2 and 6 and increment both equally one at a time?

No. Work your way through it: i starts at 2, j starts at i+1 = 3; then j goes to 4, then 5, then 6. i goes to 3; j starts at 4, goes to 5, then 6. And so on. Looks like you're not entirely clear on how a loop works.

Trying to grasp how those LEDs are named. Not just the whole array.

int NLEDS[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };

int LEDArray = sizeof(NLEDS)/sizeof(int);


I'm baffled by this. The array is nothing but a sequential list of indexes, and those indexes are really nothing more than the names you gave the LEDs - they're not connected to anything in the circuiting. The int is just 20, but you don't learn anything from it - you already told NLEDS to be 20 elements in size.

You are correct.

`digitalWrite(LEDArray[1],HIGH);`Here's what's wrong with this: LEDArray is an int, not an array. I'm thinking that this code didn't compile - is that right?

I have the time so would like to try figuring out the C monster that has found me. Will go on learning! Thanks for pointers and advice.

How would you like to proceed? We can post code that will give you the result you want, or we can help you work through it. My instincts say that you're unfamiliar with C, and with programming in general. Maybe we'd serve you best by getting this one working, and letting you get on with learning the language; maybe you'd prefer to work through this as a learning experience. How would you like to proceed?

MasterErik:
Place a # before and after?

No, not that. When you're in the reply window, there's an array of buttons marked with symbols above the text window. One of them is marked with a "#". When you push that button, "code tags" will appear in the text window at the cursor position. Paste your code between them, and your post will show it like this:< some code > ...It'll be marked as code, and everyone's browser will display it literally, and won't treat anything it finds as some sort of special character. If you want to see a special character sequence in action, try putting an "8" in parenthesis, and then push the "Preview" button.

Also, we'll be likely to get more participation if you don't quote entire messages. I'd suggest deleting the parts that you're not directly addressing from your reply. I think that viewers see long stretches of quoted text, think the post is likely to be boring, and move on without reading.

Ah, useful buttons. New concept. Gotcha. Will use the buttons.

Makes just 2 through 6 input.

(uint8_t i=2;i<=6;i++)

This increases j +1 but not over 6.

for (uint8_t j=i+1;j<=6;j++)

Makes uint8_t increase. or the i++ makes i increase and j++ makes j increase.

 n++

Makes it go to 20 integer... i and j go to 20 each. But they are only allowed to go to 6. So that is the loop.
i= 2 3 4 5 6 2 3 4 5 6 2 3 4 5 6 2 3 4 5 6
j= 3 4 5 6 ? 3 4 5 6 ? 3 4 5 6 ? 3 4 5 6 ?
But that makes it do the same over and over again. Hmm.

Ok, glad to be at work. haha

So wrote this and modified x and y to determine the values of the pins to the leds. Wow, what a pretty pattern!

void loop () {
   uint8_t n = 0;
   for (uint8_t a=x;a<=6;) {
     pinMode (a,OUTPUT);
     for (uint8_t b=y;b<=6;) {
       pinMode (b,OUTPUT);
       digitalWrite(a,HIGH);

2,3=1
3,2=2
3,4=3
4,3=4
4,5=5
5,4=6
5,6=7
6,5=8
2,4=9
4,2=10
3,5=11
5,3=12
4,6=13
6,4=14
2,5=15
5,2=16
3,6=17
6,3=18
2,6=19
6,2=20

what is the purpose of

uint8_t n = 0; n++