Hi there,
Recently I've been working on making a binary clock using the arduino duemilanove. I created a charlieplexed network containing 24 LEDs, which are connected from pin 2 through to 7. As you probably know, charliplex networks only allow one LED to be turned on at the time, so if multiple LEDs must be turned on, the optical illusion 'flickering' is used, where all the required LEDs are turned on one after the other, at a rate greater the the human eyesight framerate.
After having built the LED network I wrote a script (test1.pde in the attatched files) to test the network. With a delay of 1 second between each LED lighting up, all 24 LEDs in the network lit up correctly.
When i took out the delay (test2.pde in the attatched files) to make it appear as though they all lit up together however, some LEDs lit up brighter than others. Initially i had different colour LEDs for each column of the binary clock so I tried changing all the LEDs to standard brightness yellow LEDs to see if the different power ratings of the previously used LEDs was the problem. No luck, some LEDs in the network persistently light brighter than others. I tried switching the positions of one of the LEDs which lit brightly, with one which was dimmer. The dim one became bright and the bright one turned dim. So the LEDs in themselves are not the problem.
What could the issue causing this changing in brightness be? Could it be an issue with the time it takes the arduino to set an individual pin to OUTPUT mode and to a HIGH state which is causing this problem? Or are the 470 Ohm resistors I've attached to each pin as shown in the attatched schematic too large? Or could the breadboard's internal conenctions have different resistances in some points which are causing the changes in brightness (the breadboard is new)?
I was wondering if the issue could be solved in any way, either by changing the network or electronic setup of the binary clock, or by changing the code which runs the binary (BinaryClockSketch.pde in the attatchments)? Any help would be greatly appreciated.
Thanks
triple-xxxx
[edit]Here is a link to all the files mentioned in the question:
The reason why some LEDs are brighter than others is that they are on for a longer time than the others.
This is down to the way the software is written and is possibly unavoidable.
The reason why some LEDs are brighter than others is that they are on for a longer time than the others.
This is down to the way the software is written and is possibly unavoidable.
How is this possible though? In test two where I tested each idividual LED taking out the one second delay, the difference in brightness still shows up even though the time each LED is on should be the same as the code is repeated in exactly the same way for each LED. Shouldn't this mean that because the arduino goes through the same code each time to turn on and LED, that each LED should light for the same amount of time and in the same way?
How about, instead of removing all delays and letting program execution determine the LED on-time, you add back a small delay making a framerate of say 50 Hz or something easily determinable (and making program execution "delays" insignificant).
A delay(1) would be 41.6667 Hz for the 24 LEDs, but the accuracy of the delay for one millisecond is not the best, as I understand it. Use delayMicroseconds() instead. I usually detest delay() and delayMicroseconds(), since they halt program execution, but sometimes they are OK. Especially for quick tests.
Better than delay/Microseconds make a timer variable and time it (or use interrupts).
How about, instead of removing all delays and letting program execution determine the LED on-time, you add back a small delay making a framerate of say 50 Hz or something easily determinable (and making program execution "delays" insignificant).
A delay(1) would be 41.6667 Hz for the 24 LEDs, but the accuracy of the delay for one millisecond is not the best, as I understand it. Use delayMicroseconds() instead. I usually detest delay() and delayMicroseconds(), since they halt program execution, but sometimes they are OK. Especially for quick tests.
Better than delay/Microseconds make a timer variable and time it (or use interrupts).
Indeed I tried a while back changing the delays to delay(0) and that seemed to solve the problem. All the LEDs did light up more or less with the same brightness. However as you said the delay command stops whatever the arduino is doing for tha period of time. If I apply this method to the BinaryClockSketch.pde it would make the sketch useless as the whole point of the sketch is to keep time. If I add the delays then the arduino won't be able to efficiently keep time, but it will start running slow quite soon.
Would using interrupts work better? and if so how would I use them? I've never tried them before and so have no experience with them whatsoever.
All the LEDs did light up more or less with the same brightness.
So that proves the problem is software.
If I add the delays then the arduino won't be able to efficiently keep time, but it will start running slow quite soon.
Not if you wrote the program correctly and had the millis() counter keeping track of the time and your refresh loop doing it's own thing. Then you could use delays without affecting the keeping track of time. There is no need to resort to using interrupts which would not help you much anyway.