I have a sketch that grabs a string of data from serial input.
Since im a lame noob I "tricked" the LCD and just added a bunch of spaces in the string to make it format nicely on the LCD in 2 lines.
$ Air Temp: 70F CO2:450 Hum:50#
Well now I want to display the above on 2 lines and then scroll it offscreen to another similar string.
Adding some simple code like
for (int x=0; x<31; x++) {
led.scrollLeft();
delay(500);
}
or something to that effect. ive only started playing with the LCD today.
But then I got to thinking. Once ive scrolled to the next screen im not sure how or where to loop it so it keeps going between the pages. The main issue is my checkserial function to parse the start and stop bits is what loops and then calls the LCD once at the end. Since I only call the UpdateLCD script ever few minutes the LCD would only display the loop once and then be stuck on whatever the last screen is for the next few minutes.
#include <SoftwareSerial.h>
#include <SparkFunSerLCD.h>
SparkFunSerLCD led(2,2,16); // desired pin, rows, cols
char string[66];
int curWritePos;
void setup () {
Serial.begin(9600);
led.setup();
delay(1000);
led.off();
delay(1000);
led.on();
// led.at(2,7,"m:");
led.cursorOff();
curWritePos=0;
string[curWritePos]=0;
}
void loop () {
int availableBytes = Serial.available();
if (availableBytes > 0)
{
for(int i=0; i<availableBytes; i++)
{
int ch = Serial.read();
switch(ch)
{
case '#':
// Serial.println(string);
displaycrap();
curWritePos=0;
string[curWritePos]=0;
break;
case '
:
curWritePos=0;
string[curWritePos]=0;
break;
case '@':
default:
if (curWritePos < sizeof(string)-1)
{
string[curWritePos++]=ch;
string[curWritePos]=0;
}
else
{
// Serial.println("Overflow\n");
}
break;
}
}
}
}
void displaycrap() {
////////// GET DATA FROM PHP
led.empty();
led.at(1,1,string);
for (int x=0; x<31; x++) {
led.scrollRight();
delay(500);
}
for (int x=0; x<31; x++) {
led.scrollLeft();
delay(500);
}
led.cursorOff();
}