I am attempting to charlieplex 9 LEDs using 4 pins of an Uno. I can light up an individual LED but don't understand how to light up several at the same time. CAn anyone explain the correct way to do this?
I have a version I'm working on online at Tinkercad here: https://www.tinkercad.com/things/4vsov86j8ca-charlieplexing-2/
Here is my code:
const int UPPERPIN = 13; //upmost pin
const int LOWERPIN = 10; //lowest pin
void setup()
{
}
void loop()
{
//update the leds
updatePins();
}
//the function which manages the leds
void updatePins()
{
// Each of these seem to work individually but not together.
//LED 2
pinMode(11, OUTPUT);
digitalWrite(11, HIGH);
pinMode(13, INPUT);
digitalWrite(13, HIGH);
//LED 8
pinMode(12, INPUT);
digitalWrite(12, HIGH);
pinMode(11, OUTPUT);
digitalWrite(11, LOW);
delay(1000);
//reset all LEDs
resetAllPins();
}
void resetAllPins()
{
for(int i = LOWERPIN; i <= UPPERPIN; i++)
{
pinMode(i, INPUT);
digitalWrite(i, LOW);
}
//set everything to high impendance, so it will not function in the circuit
}
As you say you can turn on individual LEDs but you don't know how to turn on two LEDs at the same time I take from your question that you did not understand Charlieplexing at all.
Charlieplexing is a special form of multiplexing. It uses the tri-state capabilities of I/O pins to reduce the nubmer of pins compared to traditional multiplexing.
Let's take the most simple example
With both X1 and X2 as outputs having X1 high and X2 low state will turn on LED 1, X1 low and X2 high state will turn LED2 on
It is obvious that you cannot turn LED1 and LED2 on at the same time.
But you can make it look like they're on at the same time abusing persistance of human vision. If the you blink 1 led fast enough it will look like it is on the whole time. So all you have to do is to blink LED1 and LED2 alternatingly with that freuqency.