Scroll function
Tumbler
Posts: 323
Hello
I'm trying to make a scroll function for the 4x20 lcd
When i send a string it will be copied to display[noparse][[/noparse]4]
during a scroll every line scrolls up, and the display[noparse][[/noparse]4] line shows in the LCD
but when i send another string, the screen scrolls up like it has to do, but the last 2 lines have the same text. (last send string)
And i'm not know what i'm doing wrong here
example
first time i start the program
output to lcd
1
2
3
4
now i send "PARALLAX"
displays shows
2
3
4
PARALLAX
send another string: "JAVELIN"
display shows now:
3
4
JAVELIN
JAVELIN
Post Edited (Tumbler) : 6/14/2009 10:40:05 AM GMT
I'm trying to make a scroll function for the 4x20 lcd
public static void main() {
Uart txOut = new Uart(Uart.dirTransmit, LCD_PIN, Uart.dontInvert,
Uart.speed19200,Uart.stop1);
Serial_LCD4x20 myLCD = new Serial_LCD4x20(txOut);
myLCD.clearDisplay();
String [noparse][[/noparse]] display;
display = new String[noparse][[/noparse]5];
display[noparse][[/noparse]0] ="1 "; //lcd module line 1
display[noparse][[/noparse]1] ="2 "; //lcd module line 2
display[noparse][[/noparse]2] ="3 "; //lcd module line 3
display[noparse][[/noparse]3] ="4 "; //lcd module line 4
display[noparse][[/noparse]4] =" "; //
StringBuffer buf= new StringBuffer(255);
boolean scroll=false;
while(true){ // endless loop
while(rxUart.byteAvailable()){ // look if received data
char c=(char)rxUart.receiveByte(); // get the data
buf.append(c); // and put into buffer
scroll=true;
}
display[noparse][[/noparse]4]=buf.toString(); //copy buf to display line 4
buf.clear(); // empty the buffer
if(scroll){
//scroll display array
for(int i=0;i<4;i++){
System.out.println("Copy display line ("+(i+1)+") to display line ("+i+"):"+ display[noparse][[/noparse]i+1]+"->"+display[noparse][[/noparse]i]);
display[noparse][[/noparse]i]=display[noparse][[/noparse]i+1]; // copy display line i+1 to display line i
}//end for
// copy display array into lcd
for(int i=0;i<4;i++){
myLCD.setPosition(i,0);
myLCD.write(display[noparse][[/noparse]i]);
}// end for
scroll=false;
}//end if(scroll)
}//end while
}//end main
When i send a string it will be copied to display[noparse][[/noparse]4]
during a scroll every line scrolls up, and the display[noparse][[/noparse]4] line shows in the LCD
but when i send another string, the screen scrolls up like it has to do, but the last 2 lines have the same text. (last send string)
And i'm not know what i'm doing wrong here

example
first time i start the program
output to lcd
1
2
3
4
now i send "PARALLAX"
displays shows
2
3
4
PARALLAX
send another string: "JAVELIN"
display shows now:
3
4
JAVELIN
JAVELIN
Post Edited (Tumbler) : 6/14/2009 10:40:05 AM GMT

Comments
rather than the string contents.
You need to rotate the string pointers (better use string buffers)
[size=2][code] public static void main() { Uart txOut = new Uart(Uart.dirTransmit, LCD_PIN, Uart.dontInvert, Uart.speed19200,Uart.stop1); Serial_LCD4x20 myLCD = new Serial_LCD4x20(txOut); myLCD.clearDisplay(); StringBuffer[noparse][[/noparse]] display = new StringBuffer[noparse][[/noparse]5]; StringBuffer Temp; for (int i=0; i<5; i++) { display[noparse][[/noparse]i] = new StringBuffer(); } display[noparse][[/noparse]0].Append("1 "); //lcd module line 1 display[noparse][[/noparse]1].Append("2 "); //lcd module line 2 display[noparse][[/noparse]2].Append("3 "); //lcd module line 3 display[noparse][[/noparse]3].Append("4 "); //lcd module line 4 boolean scroll=false; while(true){ // endless loop while(rxUart.byteAvailable()){ // look if received data char c=(char)rxUart.receiveByte(); // get the data display[noparse][[/noparse]4].append(c); // and put into buffer scroll=true; } if(scroll){ //scroll display array (rotate buffer pointers) Temp = display[noparse][[/noparse]0]; display[noparse][[/noparse]0] = display[noparse][[/noparse]1]; display[noparse][[/noparse]1] = display[noparse][[/noparse]2]; display[noparse][[/noparse]2] = display[noparse][[/noparse]3]; display[noparse][[/noparse]3] = display[noparse][[/noparse]4]; display[noparse][[/noparse]4] = Temp; display[noparse][[/noparse]4].Clear(); //will be filled with received bytes // copy display array into lcd for(int i=0;i<4;i++){ myLCD.setPosition(i,0); myLCD.write(display[noparse][[/noparse]i]); }// end for scroll=false; }//end if(scroll) }//end while }//end main[/code][/size]
regards peter
·