Hi
Well, i tried to copy the function as suggested. made a few attempts to see if it can print the message to LCD even for one time, not to mention several by using the counters.
But all i got was a flashing one character at position 1,0 of the LCD
it is probably my mistake not to mention that the function does not scroll even once.
The truth is that i feel a bit frastrated that i could not resolve the reason myself !!
The first error i got was at the following line of code of the function :
if (positionCounter[line] == 0 || (positionCounter[line] = strlen(text) + LEDLINE - 1))
which disappered when i added the pranteses.
The total scetch is presented herein, no clue how to get forward.
My objective is to read text stored in SD card that might be more than 100 char and than print it on the LCD, slow that people can read and allow to do that several times and move on with the program
will appreciate clues how break the code into chunks I can understand and move further.
P.S. I succeded in writing to the LCD other chunjs of text as suggested in many simple examples
Moshiko
/* this program shows how to write long text messages on LCD by scrolling*/
// define the chars in one LED line
#define LEDLINE 16
#include <LiquidCrystal_I2C.h>
#include <Wire.h> // Comes with Arduino IDE, needed for I2C communication
/*
* I2C interface card for LCD, 16 chars 2 line display
* I2C interface card connection: GND, Vcc 5v, SDA to pin A4, SCL to pin A5
* LCD_I2c adrees 0x3F
*/
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
// define scrolling speed for two LED lines
const int ledScrollSpeed[2]={445,450};
// define scrolling direction for two LED lines (true means right-to-left scrolling)
const boolean ledScrollDir[2]={true,true};
/////////// function to check position of the character //////////////
char charAt(char *text, int pos)
// scrolling-logic coded here
{
if (pos<LEDLINE) return ' '; // scroll in
else if (pos>=LEDLINE && pos<LEDLINE+strlen(text))
return text[pos-LEDLINE]; // scroll text
else return ' '; // scroll out
}
/////////////////////////////////////////////////////////////////
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 1);
}
void loop() {
// variable to count number of 'scrolls'; one for each line; by default initialised to 0
static byte scrollCount[2];
// Scroll text in line number 0
if (scroll_text("This text is for top line, it is long ", 0) == true)
{
scrollCount[0]++;
}
// Scroll text in line number 1
if (scroll_text("This on bottom", 1) == true)
{
scrollCount[1]++;
}
// if either scrollCount has not reached the number of scrolls
if (scrollCount[0] != 5 || scrollCount[1] != 5)
{
// nothing else to do
return;
}
}
////////////////////////////////////////////////
/* this function scrolles the test on top or botoom line on the LCD
according to the line parameter
*/
bool scroll_text(char *text, byte line)
// scroll the LED lines
{
char currenttext[LEDLINE + 1];
static unsigned long nextscroll[2];
static int positionCounter[2];
int i;
if (millis() > nextscroll[line])
{
nextscroll[line] = millis() + ledScrollSpeed[line];
for (i = 0; i < LEDLINE; i++)
currenttext[i] = charAt(text, positionCounter[line] + i);
currenttext[LEDLINE] = 0;
lcd.setCursor(0, line);
lcd.print(currenttext);
if (ledScrollDir[line])
{
positionCounter[line]++;
if (positionCounter[line] == strlen(text) + LEDLINE) positionCounter[line] = 0;
}
else
{
positionCounter[line]--;
if (positionCounter[line] < 0) positionCounter[line] = strlen(text) + LEDLINE - 1;
}
}
// if scroll was done, return true, if scroll is still in progress return false
if (positionCounter[line] == 0 || (positionCounter[line] = strlen(text) + LEDLINE - 1))
{
return true;
}
else
{
return false;
}
}
/////////// end of function /////////////////////////////////////////////////