parsing words from serial.read() to display on LCD

Hello,

I have an RSS feed that is being read from a Python script into my Arduino UNO to display on a standard LCD Screen. It currently wraps from line 1 to line 2 once line 1 is full. If line 2 is full it clears to a new screen. At the end of feed, the screen clears ready for the next. This works quite well.

The next thing I want it to do is line-wrap if the word does not fit on the line, rather than just filling the line completely and wrapping half-way through a word.

My thoughts on doing this are:

Using " " character to detect when a word starts and finishes and read incoming bytes into an Array, so:

“Welcome to the ten oclock news”, would be

Array[0] = “Welcome”
Array[1] = “to”
Array[3] = “the”…and so on.

Then perform a string count on how big the array is, if there is enough room on the current line, print, if not, print to the next line.

My code is below - can anyone please point me in the right direction to do this?

Thanks

int startstring = 0;
int charcount = 0;
int linetwo = 0;
int clearOnce = 0;
const int initialMarker = 1;


#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void newfeed(){
    digitalWrite(10,HIGH); 
    digitalWrite(10,LOW);
    charcount = 0;
    linetwo = 0;
    lcd.setCursor(0,0);
}
 

void setup(){
  delay (2000);
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  pinMode(13, OUTPUT); 
  pinMode(10, OUTPUT); 
  Serial.println(initialMarker); // print startMarker once
}

void loop(){
  char incomingByte = 0;
    if (Serial.available() > 0){
      digitalWrite(13,HIGH);
      incomingByte = Serial.read();
     
      if (incomingByte == '<') {
        newfeed(); 
      }
      
      
      if (charcount < 16) {
          lcd.print(incomingByte);
          charcount++ ;
         }
          else if ((charcount >= 16) && (charcount <=31)){
            if (linetwo == 0) {
              lcd.setCursor(0,1);
              linetwo = 1;
              
            }
            lcd.print(incomingByte);
            charcount++ ;
           }
          else if (charcount == 32){
              charcount = 0;
              lcd.setCursor(0,0);
              delay (2000);
              lcd.clear();
              lcd.print(incomingByte);
              charcount ++;
              linetwo = 0;
           }

    digitalWrite(13, LOW);
    delay(10);
       }
}

You will need to save the incoming letters in an array, so you can do something with the word, once a space arrives, indicating the end of a word. You are not currently doing that.

The 2nd example in Serial Input Basics will save all the data into an char array. There is a parse example that can be used to break it into words.

It probably does not make sense to write each word into a array. I would just pick out each word in turn, detect its length and, if it will fit, put it on Line1.

...R