Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------------------------
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,16,2); // select the pins used on the LCD panel
- const byte numBytes = 255;
- char line1[numBytes];
- char line2[numBytes];
- byte line1b = 0;
- byte line2b = 0;
- //----------------------------------
- int Li = 16;
- int Lii = 0;
- int Ri = -1;
- int Rii = -1;
- //----------------------------------
- void setup(){
- lcd.init(); // start the LCD library
- lcd.backlight();
- Serial.begin(9600);
- }
- //----------------------------------
- void loop(){
- processdata();
- lcd.setCursor(0,1);
- lcd.print(line2);
- lcd.setCursor(0, 0);
- lcd.print(Scroll_LCD_Left(line1));
- delay(250);
- if(Lii==1) {delay(2000);} //wait 2 seconds before starting scroll
- }
- //----------------------------------
- String Scroll_LCD_Left(String StrDisplay){
- String result;
- if (StrDisplay.length() < 17) { // why scroll if we're under 16 characters?
- result = StrDisplay;
- return result;
- }
- String StrProcess = StrDisplay + " ";
- result = StrProcess.substring(Li,Lii);
- Li++;
- Lii++;
- if (Li>StrProcess.length()){
- Li=16;
- Lii=0;
- }
- return result;
- }
- void Clear_Scroll_LCD_Left(){
- Li=16;
- Lii=0;
- }
- void processdata() {
- int ndx = 0;
- byte startMarker = 0x02;
- char linebreak = '\n';
- byte endMarker = 0x04;
- char rb;
- int topline;
- topline = 1;
- while (Serial.available() > 0) {
- rb = Serial.read();
- if (topline == 1) {
- if (rb == linebreak) {
- line1[ndx] = '\0';
- line1b = ndx;
- topline = 0;
- ndx=0;
- Clear_Scroll_LCD_Left();
- }
- else {
- line1[ndx] = rb;
- ndx++;
- }
- }
- else {
- if (rb == linebreak) {
- line2[ndx] = '\0';
- line2b = ndx;
- Serial.flush();
- clearLCDbuffer();
- }
- else {
- line2[ndx] = rb;
- ndx++;
- }
- }}
- }
- void clearLCDbuffer() {
- lcd.setCursor(0,0);
- lcd.print(" ");
- lcd.setCursor(0,1);
- lcd.print(" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement