A couple things to note (basically just direct port manipulation warnings):
-- This will likely only work as-is with the Atmega168/328. The registers are different on different microcontrollers. If you're using something else make sure and research your registers first.
-- This requires you to know your CI/DI pins at compile-time as they are then hard-coded (I used the same pins as the Adafruit tutorial for this code, 2=data, 3=clock)
-- Be careful if you modify this to not mess with digital pins 0 & 1. They're your serial pins and can be a big headache reprogramming your Arduino if you accidentally change their I/O mode.
Just replace the write8() function in the LPD8806.c file with this code for a substantially faster framerate (old digitalWrite code left commented out for readability). Also, if anyone else has any similar tricks to better push this strip throw them in here. I'd love to hear them as I'm working on prototyping a fair sized project using these.
- Code: Select all | TOGGLE FULL SIZE
//Hard-coded direct port manipulation assuming DI=pin2 and CI=pin3
void LPD8806::write8(uint8_t d)
{
for (uint8_t i=0; i<8; i++)
{
if (d & _BV(7-i))
//digitalWrite(dataPin, HIGH);
PORTD |= B00000100; // sets data pin (2) HIGH leaving 0 & 1 alone
else
//digitalWrite(dataPin, LOW);
PORTD &= B11111011; // sets data pin (2) LOW leaving 0 & 1 alone
//Set clock pin (3) high then low (leaving 0 & 1 alone)
//digitalWrite(clockPin, HIGH);
PORTD |= B00001000;
//digitalWrite(clockPin, LOW);
PORTD &= B11110111;
}
}