Help implement queue for ticker?

Hi, I am trying to make a desktop ticker using some cool displays I have.

I'd like to print a stream of serial data to the display. I have a function where I can print a char to any location on the display like this:

void displayChar(char myChar, int myPos, byte myDisp){
......
......    (left out I2C wire commands that write data to an MCP23017)
......
}

So if I say:

displayChar('A', 4, 0);

the letter A would print in the fourth position on the display.

I also have a function for displaying a character array that looks like this:

void showMessage(){
    for (int i = 8; i > 0; i--){
        displayChar(message[i-1], i-1, 0);
    } 
  
}

Where I have :

char message[9] = "01234567";

The display looks like: 01234567.

What I need help on is reading data with Serial.read() and kind of pushing each byte onto the array, where every time it reads a byte, it pushes in to message[], and then I can call showMessage such that the display scrolls.

Should I approach this in a different way? is it better to just use the displayChar() function and iterate over the serial data as it comes in? Thanks for any help on this.

What I need help on is reading data with Serial.read() and kind of pushing each byte onto the array, where every time it reads a byte, it pushes in to message[], and then I can call showMessage such that the display scrolls.

Really?

   if(Serial.available() > 0)
   {
       char letter = Serial.read();
       message[index++] = letter;
       message[index] = '\0';
   }

At some point, you'll probably want to reset index to 0. You'll also need to, of course, define index as a global or static variable (of type byte, probably).

Yes, really.

I tried what you suggested, and that works ok for the first 8 serial characters. So If I write to the serial port "This is a test..."

My display looks like "This is "

So that is why what I was hoping to do was have some kind of queue where as the data arrived it would push into some kind of queue so that it would look more like:

This is 
his is a
is a tes
s a test

and so on. I'm sure it's simple, but I don't know how to do it. Maybe this is what you meant when you said I should reset the index?

Maybe it’s more like this?:

if(Serial.available() > 0)
   {
       for (byte i = 0; i < 8; i++){
           message[i] = message[i + 1];
       }
       char letter = Serial.read();
       message[7] = letter;
       showMessage();
       delay(100);
   }

So this works, up to a point. If I use this:

void loop(){
  if (Serial.available()){
       for (byte i = 0; i < 8; i++){
         message[i] = message[i + 1];
       }
       char letter = Serial.read();
       message[7] = letter;
       showMessage();
       delay(10);
  }
}

and send “This is a really long test of how you can write a stream to the display… you can write as much as you like in here”,
I only get:

This is a really long test of how you can write a stream where the end of the message is missing.

on the display. That will happen two or three times through the loop, then the display will slow down to a crawl where each char will take about 15 seconds to scroll to the next position.

Sometimes if I open the serial monitor it will “unstuck” the message and it will quickly scroll on.

I am using an Uno connected over usb and using python to write the message to the /dev/usbXXXX device.

Does anyone know where I’m going wrong?

Sounds like you want a circular buffer, ringbuffer, or FIFO.

http://forum.arduino.cc/index.php?topic=262754.msg1858132#msg1858132