This is a code stub (I think its called) as part of a much larger project. I am still struggling with functions , and how to pass variables and the correct syntax.
in my (working example) I am using a const char * scrollText to pass to my function LCDScroll.
I plan to use it for a char array of temperatures from a ds18b20 (5 of them) in proper readable text.
I can't have this as a const char as they will be changing all the time. So removing the const in the Function declaration will allow that to occur?
Also i use strlen and have cast it with unsigned int (they did that on cpluplus.com). Do I really need the cast? Also does using this function add a lot of overhead to my compile by having to include string.h (implicitly included).
Finally I had to use lcd.init() as lcd.begin() wouldn't compile for some reason. I have just noticed that the first few and the last character is being truncated so I need to figure that out too.
anyway here is my code. Hopefully someone else will find it useful as I coudn't find a function to do this after looking with google for a few days (on and off).
//written for the public domain by RajDarge.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define LCD_COLS 20 //LCD is 20x4
#define LCD_ROWS 4
LiquidCrystal_I2C lcd(0x27,LCD_COLS,LCD_ROWS);
const char * scrollText = "01234567890 ABCDEFGH IJKLMNO PQRSTUVWX YZ 01234567890\0";
const int t_textstringlength = (unsigned int) strlen(scrollText);
void setup() {
// setup the LCD panel 20x4 here.
lcd.init();
lcd.setCursor(0,0);
lcd.backlight();
lcd.print("Â Non Scrolling Text");
}
char t_chrBuffer[21];
void loop() {
lcd.setCursor(0,1);
LCDScroll(scrollText, t_chrBuffer , t_textstringlength);
lcd.print(t_chrBuffer);
delay(180);
}
// ****** - ******
// Function to scroll text
// INPUT: Txt2Scroll ----- const char string to scrollÂ
// INPUT: chrBuffer ----- Returns buffer of substring
// INPUt: txtlen -- length of char string to print
// Returns true if succesful shift, false if to end of string
void LCDScroll(const char*Â Txt2Scroll, char* chrBuffer, int txtLen)
{
 static int charIndex; //AVOIDING A GLOBAL
 if ((charIndex + LCD_COLS) > txtLen)
  charIndex = 0; //don't drop off the end of the earth
Â
 for(int x = 0; x < LCD_COLS; x++)
  { // buffer containes string of LCD_COLS
   chrBuffer[x]= Txt2Scroll[charIndex + x];
  }
 charIndex++;
}