- #1
bremenfallturm
- 71
- 11
- TL;DR Summary
- I have made a basic code to Charlieplex a bunch of LEDs. I have the problem that the last LED I am trying to turn on in the circuit appears much brighter than the others. Why?
Hi!
I am questioning my design choices, but I will try to push this circuit a little more until I get a microcontroller with more pins and don't use Charlieplexing.
Charlieplexing is a method of controlling n*(n-1), in this case LEDs, using n GPIO pins. This is achieved by alternating the state of pins: high, low, or input.
What I want to do:
I am trying to create a countdown timer circuit. The timer is going to light up between 1 and 12 LEDs, acting like a progressbar to show the time left. Also, the last LED will blink every second, so the progress bar indicates that the timer is counting down.
See the picture above for what I am trying to build:
So my requirements are:
* Must be able to address/control all 12 LEDs individually (sometimes I might need to turn on one of them, sometimes two, sometimes all, and so on).
* The rightmost LED of the lit-up LEDs must blink, like in the picture above.
I tried to use Charlieplexing (explained above) so I could get away with a microcontroller with few pins.
My problem:
I built a standard Charlieplexing circuit to control 12 LEDs (see for example: http://www.multiwingspan.co.uk/arduino.php?page=charlie) on a breadboard.
To get LEDs lit up at the same time, I use a very small delay between when each pin is updated.
I get all the LEDs to appear lit up simultaneously, however, the LED that is supposed to blink (see the image above) somehow appears brighter than the other LEDs.
This is the code that I run on an Arduino UNO (the Charliplexing pins used are 13,12,11 and 10):
In the video below, I run the code above, which is expected to be turn on 8 of the 12 LEDs and the uneven brightness issue can be illustrated. Watch the video and you can see that these LEDs (LED 7 and 8) are always brighter than the rest:
(the breadboard connection won't win awards, I know...)
I did not connect the LEDs on my breadboard circuit in a logical order - hope you can bear with that. The 8th LED is supposed to alternate between on and off like in the image I provided above.
My setup gives me uneven brightness on just the last LED I want to illuminate. Why? Is it a timing problem with my code? Circuit issue? Charlieplexing limitation?
Many thanks for your help!
Some complementary information:
The LEDs are all identical. They are rated: Red at 20 mA: 1,92-2,06 V. I run them on an Arduino UNO with 150ohm resistors between each pin and the rest of the connections that the pin has.
I am questioning my design choices, but I will try to push this circuit a little more until I get a microcontroller with more pins and don't use Charlieplexing.
Charlieplexing is a method of controlling n*(n-1), in this case LEDs, using n GPIO pins. This is achieved by alternating the state of pins: high, low, or input.
What I want to do:
I am trying to create a countdown timer circuit. The timer is going to light up between 1 and 12 LEDs, acting like a progressbar to show the time left. Also, the last LED will blink every second, so the progress bar indicates that the timer is counting down.
See the picture above for what I am trying to build:
So my requirements are:
* Must be able to address/control all 12 LEDs individually (sometimes I might need to turn on one of them, sometimes two, sometimes all, and so on).
* The rightmost LED of the lit-up LEDs must blink, like in the picture above.
I tried to use Charlieplexing (explained above) so I could get away with a microcontroller with few pins.
My problem:
I built a standard Charlieplexing circuit to control 12 LEDs (see for example: http://www.multiwingspan.co.uk/arduino.php?page=charlie) on a breadboard.
To get LEDs lit up at the same time, I use a very small delay between when each pin is updated.
I get all the LEDs to appear lit up simultaneously, however, the LED that is supposed to blink (see the image above) somehow appears brighter than the other LEDs.
This is the code that I run on an Arduino UNO (the Charliplexing pins used are 13,12,11 and 10):
C++:
/* charlieplexing_12_pins.ino
Test Arduino sketch (to run on an Arduino UNO, not Attinys)
for testing 12-pin Charlieplexing.
*/
const char allPinStates[12][4] = {
{
1,
0,
-1,
-1
}, // LED 1
{
0,
1,
-1,
-1
}, // LED 2
{
1,
-1,
0,
-1
}, // LED 3
{
0,
-1,
1,
-1
}, // LED 4
{
1,
-1,
-1,
0
}, // LED 5
{
0,
-1,
-1,
1
}, // LED 6
{
-1,
1,
0,
-1
}, // LED 7
{
-1,
0,
1,
-1
}, // LED 8
{
-1,
1,
-1,
0
}, // LED 9
{
-1,
0,
-1,
1
}, // LED 10
{
-1,
-1,
1,
0
}, // LED 11
{
-1,
-1,
0,
1
} // LED 12
};
const char gpioPins[4] = {
13,
12,
11,
10
};
// Used to set the 4 used pins to their wanted state
// pinStates is a pointer to a const char[] with 4 entries,
// each entry indicating the state of each GPIO pin:
// 1: Pin should be OUTPUT+ON
// 0: Pin should be OFF+OFF
// -1: Pin should be input
void setPinState(const char* pinStates){
for (int j = 0; j < 4; j++) {
const char pinState = * (pinStates + j);
const char gpioPin = gpioPins[j];
if (pinState != -1) {
pinMode(gpioPin, OUTPUT);
digitalWrite(gpioPin, pinState);
} else {
pinMode(gpioPin, INPUT);
}
}
}
// Later intended to be used as a progress bar for the timer,
// to indicate time left, by only having turned on for example LED 1,2,3, and 4.
char numberOfLEDsOn = 8;
// Used to blink the rightmost LED on the progressbar every second,
// keeping all other LEDs before it on, to indicate that the timer
// is counting down.
short timeElapsed = 0;
char blinkState = 0;
void setup() {
}
void loop() {
// Turn on all LEDs up until the LED to blink (see comments around "timeElapsed") above
for (int i = 0; i < numberOfLEDsOn-1; i++) {
// For each pin state, set the LEDs accordingly
setPinState(allPinStates[i]);
}
// Blink last LED in progressbar every second. See comments around "timeElapsed") above.
if (blinkState){
setPinState(allPinStates[numberOfLEDsOn-1]);
}
delay(1);
timeElapsed++;
// Update blinkState every second
if (timeElapsed >= 1000){
timeElapsed = 0;
blinkState = !blinkState;
}
}
In the video below, I run the code above, which is expected to be turn on 8 of the 12 LEDs and the uneven brightness issue can be illustrated. Watch the video and you can see that these LEDs (LED 7 and 8) are always brighter than the rest:
(the breadboard connection won't win awards, I know...)
I did not connect the LEDs on my breadboard circuit in a logical order - hope you can bear with that. The 8th LED is supposed to alternate between on and off like in the image I provided above.
My setup gives me uneven brightness on just the last LED I want to illuminate. Why? Is it a timing problem with my code? Circuit issue? Charlieplexing limitation?
Many thanks for your help!
Some complementary information:
The LEDs are all identical. They are rated: Red at 20 mA: 1,92-2,06 V. I run them on an Arduino UNO with 150ohm resistors between each pin and the rest of the connections that the pin has.