I don't usually like posting code of a work in progress since it can get pretty messy, I like to polish it first. But, my ISR is:
void pulseLeds()
{
static int i = 0;
i = (i + 1) % 3;
switch(i) // disply one colour each interrupt call
{
case 0:
digitalWrite(BLUE, HIGH); // Turn off blue LEDs
setAnodes(RedByte); // Set the anodes for red
digitalWrite(RED, LOW); // Turn on the red LEDs
break;
case 1:
digitalWrite(RED, HIGH);
setAnodes(GreenByte);
digitalWrite(GREEN, LOW);
break;
case 2:
digitalWrite(GREEN, HIGH);
setAnodes(BlueByte);
digitalWrite(BLUE, LOW);
break;
}
}
Obviously, setAnodes() is a simple function to break down the byte and load it onto the Anode, which have their pin numbers stored in an array.
I do use digitalWrite() for now, since timing isn't very critical, the only issue is not stealing too many cycles from the main program. It's responsive enough to do a colour persistance-of-vision display, which is something I had in mind for it.
Would there be any interest in a shield kit for this? I could get fancy and leave space for sensors on the analog inputs as well.