So, I got to thinking (with the help of some friends) about the
current sourcing capabilities of the pins on the Gadgeteer main
board. Modern microprocessors generally aren't set up to be able to
provide much current to things like LEDs. I saw a fair bit of
that with the results I was getting with the scanner.
So, what about wiring in reverse?
LEDs can be wired in two different directions. The first, which
I used yesterday is to use the microcontroller
as a current source. There's going to be a fair bit of variation
here, and the MCU really can't source much current to begin
with.
The other approach is to use the MCU as a current sink.
You can see that in this version, the LED is reversed. Rather
than current flowing from the MCU, through the LEDs and to ground,
it flows from the power supply through the resistors and LEDs and
then to the MCU pins.
To light the digital pins then, you have to make the pins low
(ground) at this point, rather than high. The program change is a
simple reversal of the logic in the OnTimerTick method.
private void OnTimerTick(GT.Timer timer)
{
// turn off old LED
//_scannerOutput[_currentOutput].Write(false);
_scannerOutput[_currentOutput].Write(true);
if (_movingLowToHigh)
{
_currentOutput += 1;
if (_currentOutput > _scannerOutput.Length - 1)
{
// we were at the end, switch direction
_currentOutput = _scannerOutput.Length - 1;
_movingLowToHigh = false;
}
}
else
{
_currentOutput -= 1;
if (_currentOutput < 0)
{
// we were at the end, switch direction
_currentOutput = 0;
_movingLowToHigh = true;
}
}
// turn on new LED
//_scannerOutput[_currentOutput].Write(true);
_scannerOutput[_currentOutput].Write(false);
timer.Interval = new TimeSpan(0, 0, 0, 0, GetAdjustedSpeed());
}
Remember to also set the initial state of all pins to High in
the constructor as well.
This won't really even out the LED brightness, but will
somewhat. It will also put less stress on the board as it doesn't
need to provide all that current to the LEDs.