sluggish simplemessagesystem

Hi folks,

Got a deadline and am running into some speed issues.

I’m using the Matrix library and the SimpleMessageSystem library to send an array of values to turn on and off LEDs, with the Decimilla hooked up to a Max7219 ic.

When i only try to control, say, 10 LEDs, it works like a charm, i can blink away at a pretty fast clip, something like 30 ms or so. When i add more, the response gets incrementally slower, i can’t seem to squeeze more than an update of around 200 ms with sending the whole 64, despite clearing out the buffer after each case statement by sending a crate return, which SimpleMessageSystem uses to reset the incoming buffer (i’m assuming).

In Max, I have a bank of LEDs that are all being packed together and then sliced in to 7 different lists, all prepended by a character to designate where they belong, as I have set up a hashtab of sorts in the arduino code. I was originally just banging through something like (xval, yval, state) but that was way too cumbersome, so I decided i’d just send the state in sequence, using the messageGetInt function. If anyone has any idea on how to make it faster, that would be immensely awesome. I’m pretty new to all of this, so its an uphill battle.

Here is the arduino sketch:

#include <binary.h>
#include <Sprite.h>
#include <Matrix.h>
#include <SimpleMessageSystem.h>

Matrix myMatrix = Matrix(5, 7, 6);

void setup()
{

// The following command initiates the serial port at 9600 baud. Please note this is VERY SLOW!!!
// I suggest you use higher speeds in your own code. You can go up to 115200 with the USB version, that’s 12x faster
Serial.begin(115200); //Baud set at 9600 for compatibility, CHANGE!

}

void loop()
{

if (messageBuild() > 0) { // Checks to see if the message is complete and erases any previous messages

writematrix(); // Call the writematrix function
}
}

void writematrix()
{ // Write pin
switch (messageGetChar()) {
case ‘a’:
myMatrix.write(6, 7, messageGetInt());
myMatrix.write(7, 7, messageGetInt());
myMatrix.write(0, 7, messageGetInt());
myMatrix.write(1, 7, messageGetInt());
myMatrix.write(2, 7, messageGetInt());
myMatrix.write(3, 7, messageGetInt());
myMatrix.write(4, 7, messageGetInt());
myMatrix.write(5, 7, messageGetInt());
myMatrix.write(2, 6, messageGetInt());
myMatrix.write(3, 6, messageGetInt());
break;
case ‘b’:
myMatrix.write(4, 6, messageGetInt());
myMatrix.write(5, 6, messageGetInt());
myMatrix.write(6, 6, messageGetInt());
myMatrix.write(7, 6, messageGetInt());
myMatrix.write(0, 6, messageGetInt());
myMatrix.write(3, 5, messageGetInt());
myMatrix.write(4, 5, messageGetInt());
myMatrix.write(5, 5, messageGetInt());
myMatrix.write(6, 5, messageGetInt());
myMatrix.write(7, 5, messageGetInt());
break;
case ‘c’:
myMatrix.write(0, 5, messageGetInt());
myMatrix.write(1, 6, messageGetInt());
myMatrix.write(2, 4, messageGetInt());
myMatrix.write(3, 4, messageGetInt());
myMatrix.write(4, 4, messageGetInt());
myMatrix.write(5, 4, messageGetInt());
myMatrix.write(6, 4, messageGetInt());
myMatrix.write(7, 4, messageGetInt());
myMatrix.write(0, 4, messageGetInt());
myMatrix.write(1, 5, messageGetInt());
break;
case ‘d’:
myMatrix.write(2, 5, messageGetInt());
myMatrix.write(1, 3, messageGetInt());
myMatrix.write(2, 3, messageGetInt());
myMatrix.write(3, 3, messageGetInt());
myMatrix.write(4, 3, messageGetInt());
myMatrix.write(5, 3, messageGetInt());
myMatrix.write(6, 3, messageGetInt());
myMatrix.write(7, 3, messageGetInt());
myMatrix.write(0, 3, messageGetInt());
myMatrix.write(1, 4, messageGetInt());
break;
case ‘e’:
myMatrix.write(0, 1, messageGetInt());
myMatrix.write(1, 2, messageGetInt());
myMatrix.write(2, 2, messageGetInt());
myMatrix.write(3, 2, messageGetInt());
myMatrix.write(4, 2, messageGetInt());
myMatrix.write(5, 2, messageGetInt());
myMatrix.write(6, 2, messageGetInt());
myMatrix.write(7, 2, messageGetInt());
myMatrix.write(0, 2, messageGetInt());
myMatrix.write(1, 1, messageGetInt());
break;
case ‘f’:
myMatrix.write(2, 1, messageGetInt());
myMatrix.write(3, 1, messageGetInt());
myMatrix.write(4, 1, messageGetInt());
myMatrix.write(5, 1, messageGetInt());
myMatrix.write(6, 1, messageGetInt());
myMatrix.write(7, 1, messageGetInt());
myMatrix.write(4, 0, messageGetInt());
myMatrix.write(5, 0, messageGetInt());
myMatrix.write(6, 0, messageGetInt());
myMatrix.write(7, 0, messageGetInt());
break;
case ‘g’:
myMatrix.write(0, 0, messageGetInt());
myMatrix.write(1, 0, messageGetInt());
myMatrix.write(2, 0, messageGetInt());
myMatrix.write(3, 0, messageGetInt());
break;
}
}

well for one you are calling messageGetInt() a whole lot, is it changing in each case? if not you could do this

  case 'a':
    int messageInt = messageGetInt();
    myMatrix.write(6, 7, messageInt );
    myMatrix.write(7, 7, messageInt );
    myMatrix.write(0, 7, messageInt );
    myMatrix.write(1, 7, messageInt );
    myMatrix.write(2, 7, messageInt );
    myMatrix.write(3, 7, messageInt );
    myMatrix.write(4, 7, messageInt );
    myMatrix.write(5, 7, messageInt );
    myMatrix.write(2, 6, messageInt );
    myMatrix.write(3, 6, messageInt );
    break;

and repeat for each case, Will speed it up a whole lot

also couldn't you use the sprite library? makes less calls = faster!! :)