Hi all,
I've made just a basic 3-pin charlieplex setup and some code to get it running. The picture isn't very clear but you can see that there's only 3 pins running out from the Arduino and 6 LEDs on the breadboard. The reason that there's so many wires is that I tried to get a nice, neat row.
Here's the code:
(Can anyone please help me with the charlieplexlist function I've been trying to write? There's something wrong with me pointers)
/**********************************************************************\
| CHARLIEPLEXING FOR NOOBS |
| By Xepter Keedas |
| |
| You are free to use this as you wish but give credit |
| where credit is due. I coded all this myself with |
| some syntax and coding assistance provided by |
| Aaron Burke. Make sure you know what you're doing |
| in case you fry your mobo (not my fault or responsibility) |
| |
\**********************************************************************/
const int pin1 = 2; //defining the pins we are using
const int pin2 = 3;
const int pin3 = 4;
int led1 [3] = {pin1, pin2, pin3}; // order goes as follows:
int led2 [3] = {pin2, pin1, pin3}; // high pin, low pin, "input" pin
int led3 [3] = {pin2, pin3, pin1};
int led4 [3] = {pin3, pin2, pin1};
int led5 [3] = {pin1, pin3, pin2};
int led6 [3] = {pin3, pin1, pin2};
//int len(int list[]){
// return sizeof(list)/sizeof(list[0]);// trying to count the length of the list for the
//}// for loop. (my friend was doing this, not sure what it was though
int* pin [6] = {
led1, led2, led3, led4, led5, led6}; //trying to put all the led pointers in a "list" of sorts (sorry, I mainly code in Python). Help pl0x?
void charlieplex(int list[3], int seconds){ //parameters are an array of 3 values (i.e your LED array) and a time delay (in ms)
int time = seconds;
digitalWrite(list[1], LOW);
digitalWrite(list[0], HIGH);
pinMode(list[2], INPUT);
delay(time);
digitalWrite(list[0], LOW);
pinMode(list[2], OUTPUT);
}
//void charlieplexlist(int list[], int seconds){ //something wrong with the pointers, not sure what
// int time = seconds;
// for (int place = 0; place<=len(list); place++) { // need help to fix it
// digitalWrite(list[1], LOW);
// digitalWrite(list[0], HIGH);
// pinMode(list[2], INPUT);
// delay(time);
// digitalWrite(list[0], LOW);
// pinMode(list[2], OUTPUT);
// }
//}
void setup(){
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
}
void loop(){
charlieplex(led1, 1000);//Just decreases the time the LEDs are on for
charlieplex(led2, 750);//Gives a crappy descending effect
charlieplex(led3, 500);
charlieplex(led4, 250);
charlieplex(led5, 200);
charlieplex(led6, 175);
for (int timer = 0; timer <= 2000; timer++) {//seconds delay is whatever you want * ~200
charlieplex(led1, 1);
charlieplex(led2, 1);
charlieplex(led3, 1);
charlieplex(led4, 1);
charlieplex(led5, 1);
charlieplex(led6, 1);
}
//charlieplexlist(pin, 1000);
}
Any comments, improvements, queries, etc I'd be more than happy to respond.
Oh, and Happy Birthday to me! 8)
- Xepter Keedas