Display circularly scrolling text on the LCD

4 posts / 0 new
Author
Message

The aim of my experiment is to display circularly scrolling text received from main function on the LCD.The text should be displayed scrolling from first row first column to first row sixteenth column of the LCD. The text coming out from first row sixteenth column should start appearing again in first row first column.

iam getting the text is scrolling from first row first column to first row sixteenth column of LCD. but iam not getting the text coming out from first row sixteenth column should start appearing again in first row first column.

pls help me to solve this.

Attachment(s):

ranju

Last Edited: Thu. Feb 8, 2018 - 03:32 PM

Does the lcd_cursor() call really accept "-5" as a valid location?

Anyway the way I would do it is probably just to shuffle the array and keep printing in in the same place. In untested psuedo code something like:

```char text[17] = "Hello Good World";
char c;

for (n=0 n < 16; n++) {
lcd_goto(0,0);
lcd_printstring(text);
// do the string shuffle
c = text[0]; // take copy of the left most character
// shuffle all the others one place to the left
for (i = 0; i < 16; i++) {
text[i] = text[i + 1];
}
// put the saved character on the end
text[15] = c;
// just in case it's disturbed
text[16] = 0; // end of string marker
}```

If you want to scroll it the other way then:

```    // do the string shuffle
c = text[15]; // take copy of the right most character
// shuffle all the others one place to the right
for (i = 15; i > 0; i--) {
text[i] = text[i - 1];
}
// put the saved character at the start
text[0] = c;
// just in case it's disturbed
text[16] = 0; // end of string marker
```

I haven't tried this or thought it through so I could well have got the boundary conditions wrong but the idea is there.

Bottom line shuffle the text itself - before you do copy the character that is about to "disappear" - at end put that character back on the other end.

Then just keep printing the text at the same location.

OK so I had to give that a go:

```D:\c>type lcd.c
#include <stdio.h>

char text[17] = "Hello Good World";
char c;

int main(void)  {
int i, n;
for (n = 0; n < 16; n++) {
printf("%s\n", text);
// do the string shuffle
c = text[0]; // take copy of the left most character
// shuffle all the others one place to the left
for (i = 0; i < 16; i++) {
text[i] = text[i + 1];
}
// put the saved character on the end
text[15] = c;
// just in case it's disturbed
text[16] = 0; // end of string marker
}
}
D:\c>cl lcd.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86

lcd.c
Microsoft (R) Incremental Linker Version 10.00.40219.01

/out:lcd.exe
lcd.obj

D:\c>lcd
Hello Good World
ello Good WorldH
llo Good WorldHe
lo Good WorldHel
o Good WorldHell
Good WorldHello
Good WorldHello
ood WorldHello G
od WorldHello Go
d WorldHello Goo
WorldHello Good
WorldHello Good
orldHello Good W
rldHello Good Wo
ldHello Good Wor
dHello Good Worl

D:\c>
```

I believe that if these strings had all been printed at the same place on an LCD (with a delay after each to give a chance for it to be seen) this would have given the impression of scrolling.

For completeness here's the "other" version going in the opposite direction:

```D:\c>type lcd.c
#include <stdio.h>

char text[17] = "Hello Good World";
char c;

int main(void)  {
int i, n;
for (n = 0; n < 16; n++) {
printf("%s\n", text);
// do the string shuffle
c = text[15]; // take copy of the right most character
// shuffle all the others one place to the right
for (i = 15; i > 0; i--) {
text[i] = text[i - 1];
}
// put the saved character at the start
text[0] = c;
// just in case it's disturbed
text[16] = 0; // end of string marker
}
}
D:\c>lcd
Hello Good World
dHello Good Worl
ldHello Good Wor
rldHello Good Wo
orldHello Good W
WorldHello Good
WorldHello Good
d WorldHello Goo
od WorldHello Go
ood WorldHello G
Good WorldHello
Good WorldHello
o Good WorldHell
lo Good WorldHel
llo Good WorldHe
ello Good WorldH```

As this demonstrates it is ASTRONOMICALLY easier to prototype this kind of thing in a PC program - when you have the mechanism worked out only THEN move to your AVR+LCD (and a few tweaks as printf() no longer works)