I'm new at this and now trying to learn about charlieplexing. I understand the way to use 3 pins to drive 6 LEDs. The one thing I don't understand is how would I write this. I been trying to find a code so I can look over it and learn so I could write my own animation. Would anyone mind posting your code for me to look at.
1]--x--x----x----------x--
| | | |
v v A |
| | | |
2]--x--|----x--x----x--|--
| | | |
| v A A
| | | |
3]-----x-------x----x--x--
(v / A) indicate electron flow direction (down / up).
If you write:
pinMode(1,OUTPUT);
pinMode(3,OUTPUT);
pinMode(2,INPUT);
digitalWrite(1,HIGH);
digitalWrite(3,HIGH);
This will send a current through the led connected between pin 1 & 2 with the 'short' leg at pin 2
I have it connected like this Heard of Multiplexing?? what about Charlieplexing! – Invobot : Artificially intelligent . I'm just unsure how I write it though. If I could get help with the first led I should be able to figure the rest out. I know I have to have pin A B as output and pin C would be input to keep led 2 from lighting up. so I don't know if I have to have it like int led1 = ab and then have pinMode(led1, OUTPUT). Those are the part I'm a little confuse with.
When A=5v , B=0v we[ch8217]l have LED1 glowing and all other LED[ch8217]s off
When A=0v, B=5v we[ch8217]l have LED2 glowing and all other LED[ch8217]s off
unsigned char ucPinA = 10;
unsigned char ucPinB = 11;//setup
void setup()
{
pinMode(ucPinA,OUTPUT);
pinMode(ucPinB,OUTPUT);
}void loop()
{
//When A=5v , B=0v we[ch8217]l have LED1 glowing and all other LED[ch8217]s off
digitalWrite(ucPinA,HIGH);
digitalWrite(ucPinB,LOW);
delay(1000);//When A=0v, B=5v we[ch8217]l have LED2 glowing and all other LED[ch8217]s off
digitalWrite(ucPinB,HIGH);
digitalWrite(ucPinA,LOW);
delay(1000);}
Thank you for helping me out there. Now I understand that. Now I have seen some peoples have codes wrote like this:
{1,1,1,0,0,1}
{1,0,1,0,1,1}
Could I use something a long the line like:
const int num_pins = 8;
const int numPatterns=10;
int timer = 1000;
int pins[] = {2, 3, 4, 5, 6, 7, 8, 9};
Another user posted a code that uses this method for a 7 segment display and it works nicely.
Instead of the pins have something that will read each LED so all I have to do is but 1 and 0 or is that even possible.
I'll have to excuse myself, I did not quite understand what
Instead of the pins have something that will read each LED so all I have to do is but 1 and 0 or is that even possible.
means.
Could you rephrase that?
ok I'm having problem with the code. When I tell it to light led1 it also light led5 the same goes for when I light led2 it light led4. So how do I get the extra pin to not get any contact. Do I need to make one pin input to keep any electric to flow to it. I know you will always have one pin thats not connected, but the way that code is its still flowing through, unless I really don't have it connected right which I believe I do.
Do I need to make one pin input to keep any electric to flow to it.
That's exactly the point of Charlieplexing.
The I/O pins are called "tri-state" pins. It can be held high, it can be held low, it can be nearly disconnected (aka high-impedance) from the circuit. If the pin is an input, it is disconnected from the power rails, so you can drive the pin high or low yourself.
In Charlieplexing, you use three pins, and you use all three states, but the third state isn't used as a traditional input. It's just put in "input" mode (aka high-impedance state) so that it will neither source nor sink current through your LEDs.
If you have three pins, A, B, C, and you want the LED from A to B to be lit, you disconnect C by making it an input. Two LEDs are between A and B, but since they're diodes in opposite directions, only one will pass current and light up. Now repeat that concept for connecting B and C and disconnecting A. And repeat that concept for connecting A and C and disconnecting B. Voila.
Sorry about that. What I was trying to ask is can I some how put
int pins[] = {ledAB, ledBC, ledCB, ledBA, ledAC, ledCA}
that way I could use the
{1,0,0,0,0,0}
pattern to turn the leds on and off alot easier and quicker.
What I was trying to ask...
Yes, you can (and should) make it easy to express the pattern(s) of lights that you want to display. You will need to provide a small function that scans the LED patterns and decides how to drive the tri-state pins appropriately.
unsigned char ucPinA = 10;
unsigned char ucPinB = 11;
//setup
void setup()
{
pinMode(ucPinA,OUTPUT);
pinMode(ucPinB,OUTPUT);
}
void loop()
{
//When A=5v , B=0v we'l have LED1 glowing and all other LED's off
digitalWrite(ucPinA,HIGH);
digitalWrite(ucPinB,LOW);
delay(1000);
//When A=0v, B=5v we'l have LED2 glowing and all other LED's off
digitalWrite(ucPinB,HIGH);
digitalWrite(ucPinA,LOW);
delay(1000);
}
what need to be added to disconnect the pin or is it my wiring then.
Read my posting again. I tried to phrase the solution three different ways to give you what you needed to know.
Sorry I'm really new at this and have never program. So i'm learning with led. I haven't work with inputs yet only outputs. So input would be new to me thanks though.
I've made an example that walks through all 6 leds.
unsigned char ucPinA = 9;
unsigned char ucPinB = 10;
unsigned char ucPinC = 11;unsigned char ucCurrentIndex = 0;
unsigned char ucNumberOfPins = 6;
/*
|| HIGH A B B C A C
|| LOW B A C B C A
*/
boolean baStates[] = { 0 , 0 , 0 , 0 , 0 , 0 };
//setup
void setup()
{
setAllAsOutput();
}void setAllAsOutput()
{
pinMode(ucPinA,OUTPUT);
pinMode(ucPinB,OUTPUT);
pinMode(ucPinC,OUTPUT);
digitalWrite(ucPinA,HIGH);
digitalWrite(ucPinB,HIGH);
digitalWrite(ucPinC,HIGH);
}void setLedHigh(unsigned char led)
{
for( unsigned char i=0; i<ucNumberOfPins; i++ )
{
baStates = false;
- }*
- baStates[led%ucNumberOfPins] = true;*
}
void lightLeds()
{- for( unsigned char i=0; i<ucNumberOfPins; i++ )*
- {*
_ if( baStates == true)_
* {*
* switch(i)*
* {*
* case 0:*
* {*
* pinMode(ucPinC,INPUT);*
* digitalWrite(ucPinB,LOW);*
* }*
* break;*
* case 1:*
* {*
* pinMode(ucPinC,INPUT);*
* digitalWrite(ucPinA,LOW);*
* }*
* break;*
* case 2:*
* {*
* pinMode(ucPinA,INPUT);*
* digitalWrite(ucPinC,LOW);*
* }*
* break;*
* case 3:*
* {*
* pinMode(ucPinA,INPUT);*
* digitalWrite(ucPinB,LOW);*
* }*
* break;*
* case 4:*
* {*
* pinMode(ucPinB,INPUT);*
* digitalWrite(ucPinC,LOW);*
* }*
* break;*
* case 5:*
* {*
* pinMode(ucPinB,INPUT);*
* digitalWrite(ucPinA,LOW);*
* }*
* break;*
* }*
* }*
* else*
* {*
* //*
* }*
* }*
}
void loop()
{
* setAllAsOutput();*
* lightLeds();*
* setLedHigh(ucCurrentIndex++);*
* delay(1000);*
}
[/quote]
Does this point you in the right direction?
Thanks a bunch. Yea most of it make sense to me on there. I'm going to have to look over each step careful but that code will help me out. Seem a bit long but I'm sure it will get me use to more of the programming. Thanks again
No problem.
Good luck, and do not forget to report back with the results