Advertisement
nq4t

Untitled

Apr 4th, 2020
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //----------------------------------
  2. #include <LiquidCrystal_I2C.h>
  3. LiquidCrystal_I2C lcd(0x27,16,2);           // select the pins used on the LCD panel
  4.  
  5. const byte numBytes = 255;
  6. char line1[numBytes];
  7. char line2[numBytes];
  8. byte line1b = 0;
  9. byte line2b = 0;
  10. //----------------------------------
  11. int Li          = 16;
  12. int Lii         = 0;
  13. int Ri          = -1;
  14. int Rii         = -1;
  15. //----------------------------------
  16. void setup(){
  17.   lcd.init();                           // start the LCD library
  18.   lcd.backlight();
  19.   Serial.begin(9600);
  20. }
  21. //----------------------------------
  22.  
  23. void loop(){
  24.  
  25.   processdata();
  26.  
  27.   lcd.setCursor(0,1);            
  28.   lcd.print(line2);  
  29.   lcd.setCursor(0, 0);
  30.   lcd.print(Scroll_LCD_Left(line1));
  31.   delay(250);
  32.   if(Lii==1) {delay(2000);} //wait 2 seconds before starting scroll
  33.  
  34. }
  35.  
  36. //----------------------------------
  37. String Scroll_LCD_Left(String StrDisplay){
  38.   String result;
  39.   if (StrDisplay.length() < 17) { // why scroll if we're under 16 characters?
  40.     result = StrDisplay;
  41.     return result;
  42.   }
  43.   String StrProcess = StrDisplay + "                ";
  44.   result = StrProcess.substring(Li,Lii);
  45.   Li++;
  46.   Lii++;
  47.   if (Li>StrProcess.length()){
  48.     Li=16;
  49.     Lii=0;
  50.   }
  51.   return result;
  52. }
  53.  
  54. void Clear_Scroll_LCD_Left(){
  55.   Li=16;
  56.   Lii=0;
  57. }
  58. void processdata() {
  59.     int ndx = 0;
  60.     byte startMarker = 0x02;
  61.     char linebreak = '\n';
  62.     byte endMarker = 0x04;
  63.     char rb;
  64.     int topline;
  65.    
  66. topline = 1;
  67.     while (Serial.available() > 0) {
  68.         rb = Serial.read();
  69.         if (topline == 1) {          
  70.              if (rb == linebreak) {
  71.                 line1[ndx] = '\0';
  72.                 line1b = ndx;
  73.                 topline = 0;
  74.                 ndx=0;
  75.                 Clear_Scroll_LCD_Left();        
  76.              }
  77.              else {
  78.               line1[ndx] = rb;
  79.               ndx++;
  80.              }
  81.                           }
  82.              
  83.         else  {
  84.               if (rb == linebreak) {
  85.                 line2[ndx] = '\0';
  86.                 line2b = ndx;
  87.                 Serial.flush();
  88.                 clearLCDbuffer();
  89.                
  90.               }
  91.               else {
  92.                 line2[ndx] = rb;
  93.                 ndx++;
  94.               }
  95.               }}
  96.              
  97.        }
  98.  
  99. void clearLCDbuffer() {
  100.     lcd.setCursor(0,0);
  101.     lcd.print("                ");
  102.     lcd.setCursor(0,1);
  103.     lcd.print("                ");
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement