Hello everybody!
This is my first post on this forum, so forgive me if I put it in the wrong section. :.
I have been reading about charlieplexing on
The concept sounded incredibly interesting, so I set about designing some software and
hardware for it, both of which are shown below:
Hardware schematic:
Software code:
int previousByte;
int incomingByte; //variable used for storing incoming data
void setup(){
Serial.begin(9600); //start serial communication
}
void loop(){
if(Serial.available() > 0){ //if there is data available...
previousByte = incomingByte; //store the old data as previousbyte
incomingByte = Serial.read(); //read the new data
incomingByte = incomingByte - 48; //Subtract 48 form it - 0 has the ASCII value 48, so to get it back to 0, we take away 48
Serial.flush(); //clear the serial 'data bank'
}
if(incomingByte != previousByte){ //if the new data is different to the old suuff...
//turn all pins to output, so we can turn them to low.
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite(2, LOW); //turn all the pins low
digitalWrite(3, LOW);
digitalWrite(4, LOW);
switch(incomingByte){ //turn on the correct pins for the LED selected:
case 1:
pinMode(4, INPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
break;
case 2:
pinMode(4, INPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
break;
case 3:
pinMode(2, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
break;
case 4:
pinMode(2, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
digitalWrite(3, LOW);
break;
case 5:
pinMode(3, INPUT);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
digitalWrite(4, LOW);
break;
case 6:
pinMode(3, INPUT);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
digitalWrite(4, HIGH);
digitalWrite(4, LOW);
break;
default:
Serial.println("Please select a number between 1 and 6");
break;
}
previousByte = incomingByte; //this makes the code more efficient, by only repeating the above when needed
}
}
The code is simple, and compiles without problems. The hardware schematic was drawn in
express PCB and has the pin connections and resistor values labelled. The reason I posted this
is because I was worried about the pins. I did not want to end up breaking anything by mistake,
so:
- Will I break the input pins by feeding too much current through them?
- Does writing a pin as low couple it to ground, rather than just stopping it from being high?
I know I probably shouldn't worry about the input pins breaking, as they are being supplied
with less current than the outputs can provide. The thing I am concerned about is, surely
using a low pin as a ground pin will pour in power that is not neeeded or wanted, and wreck
havock with the inner workings of the microcontroller?
Thanks in advance for any help!
Onions.