LCDbottom/single line scrolling once issue

I have an issue with trying to achieve my goal with this script:

char message2[80] = {0};
void loop() {
if(ava == true){
for (int x = 0; x < strlen(message2); x++) {
              LCD_Juumpy_scroll(message2, 16, 1, strlen(message2)+1); //just keep calling the function
              delay(700); //make text readable
            }
}
}
void LCD_Juumpy_scroll(const char*  Txt2Scroll, int LCD_col, int t_Row, byte buff)
{
  static int charIndex = 0 ; //AVOIDING A GLOBAL
  int txtLen =  strlen(Txt2Scroll);// get the length of the text
  char chrBuffer[LCD_col+1]; //width of the sceen
  for (int x = 0; x < LCD_col; ++x) //do characters till the end
    chrBuffer[x] = char(buff); //initialize chrBuffer
  chrBuffer[LCD_col] = char(0); // put a zero at the end
  if ((charIndex + LCD_col + 1 ) > (txtLen+1)) //loop to end of cols
  {
    int x = 0; //use x for both loops must be outside for loop
    for ( ; x < (txtLen - charIndex); x++) //if off end get till the end.
    {
      chrBuffer[x] = Txt2Scroll[charIndex + x]; //grab characters form Txt2scroll from the end
    }
    int currx = x; //memorise the counter for the chrBuffer
    for ( ; x < LCD_col; x++) //continue using the x for a counter
    {
      //chrBuffer[x] = ' ';
      chrBuffer[x] = Txt2Scroll[x - currx]; //Grab the text from the beginning and attach.
    }
    if (charIndex == txtLen)
      charIndex = 0; //reset counter
      //Serial.print("end");
  }
  else
  {
    int x = 0;
    for ( ; x < LCD_col; x++)
    { // buffer containes string of LCD_col
      chrBuffer[x] = Txt2Scroll[charIndex + x];
    }
  }

  charIndex++; //update charindex
  chrBuffer[LCD_col] = char(0);
  lcd.setCursor(0, t_Row); //move to row of cursor.
  lcd.print(chrBuffer); //print it :)
}

I have found this snippet of code on the forum but the problem it was intended to loop forever and i want it to loop once because i want to print different text everytime and then space char fill the row/line until all text disappear then clear lcd. i have been trying to achieve this since yesterday but with no succcess also sometimes the scroll doesn’t work which idk why this happens especially when i change the text length.

any help will be appreciated

Thanks

If you only want to loop once, then don't repeatedly call in in loop(). The for() loop inside loop() is what accomplishes the scroll. After that completes, call a new message.

Thanks for the help but I have tried and it still loops. I have found some simpler and better code suits me but for some reason it works just once and when i send another msg to scroll and display it shows nothing on the scrolling line/row. here it is:

char line2[17] = "                 "; // initialize line2 (16 characters plus 1 null terminator)
void loop(){
for (int i = 0 ; i <= msglen + 17; i++) { // loop through the string
                update_lcd_buffer(messageFromPC2[i], messageFromPC); // update lcd with each character
                delay(500);
              }
}
void update_lcd_buffer(char c, char* cH) {
  char *buffer2 = &line2[1]; // create pointer to the second character of line2
  Serial.print(String("c "));
  Serial.println(String(c));
  strncpy(line2, buffer2, 16); // set line2 = the second character of line2 to the end
  Serial.print(String("line2"));
  Serial.println(String(line2));
  line2[15] = c; // append our new char to end of line2
  Serial.print(String("line2"));
  Serial.println(String(line2));
  lcd.clear(); // clear the screen
  lcd.setCursor(0, 0); // set cursor to beginning of first line
  lcd.print(cH);  // print the static string on the first line
  lcd.setCursor(0, 1); // set cursor to beginning of second line
  lcd.print(line2); // print line2

}

I guess the problem with the strcpy or line2 char var. can anyone help me please?

if someone helped me i would be so grateful because i am tired trying to get this task done.

Thanks

Please post your entire sketch. A snippet can not compile so I don't know how you are using it.

The problem it is huge program and has many other sensors so it will be so confusing for you and me to filter the program for just the lcd part. so i am trying to bring the part related to the issue itself.

Waiting for some help guys

Thanks

agid:
The problem it is huge program and has many other sensors so it will be so confusing for you and me to filter the program for just the lcd part. so i am trying to bring the part related to the issue itself.

Waiting for some help guys

Thanks

Surely you can make a copy of your large program and reduce it down to setup(), loop() and your scrolling function. That is the typical way of getting something to work. After you are sure it works properly, you then move it into your larger program.

Waiting for some complete sketch

LiquidCrystal lcd(11, 10, 9, 8, 7, 6);
 
char line2[17] = "                 "; // initialize line2 (16 characters plus 1 null terminator)
 
void setup() {
   lcd.begin(16, 2); //initialize lcd
}
 
void loop(){
     char str[] = "This is a scrolling string."; // string to scroll
     for (int i = 0 ; i <= sizeof(str); i++) { // loop through the string
        update_lcd_buffer(str[i]); // update lcd with each character 
        delay(500);
     }
     
 
}
 
void update_lcd_buffer(char c) {
  char *buffer = &line2[1]; // create pointer to the second character of line2
  strncpy(line2, buffer, 16); // set line2 = the second character of line2 to the end 
  line2[15] = c; // append our new char to end of line2
  lcd.clear(); // clear the screen
  lcd.setCursor(0, 0); // set cursor to beginning of first line
  lcd.print("Static string.");  // print the static string on the first line
  lcd.setCursor(0, 1); // set cursor to beginning of second line
  lcd.print(line2); // print line2
  
}

Here we go this is the working code but mine just have bluetooth module that i send to it msg and it works for the first time but then when i send second time it doesn’t show the scolling string anymore

agid:
Here we go this is the working code but mine just have bluetooth module that i send to it msg and it works for the first time but then when i send second time it doesn't show the scolling string anymore

Ho hum. Again we can’t help with code you don’t show us....

agid:
Here we go this is the working code but mine just have bluetooth module that i send to it msg and it works for the first time but then when i send second time it doesn’t show the scolling string anymore

So how do you know the scrolling function is the problem? Are you sure you are receiving your bluetooth messages properly? Does the example code you posted display your issue or does it work fine?

I figured out that i needed to put the line2 var through it initial state to work because it changed through the function and now it works well even when i send several different messages. Thanks alot for your help blh64. adding karma