LCD Scrolling Text Only single row







Arduino Sketch code


//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

int screenWidth = 16;
int screenHeight = 2;


String line1 = " Maker Tutor "; // Static line
String line2 = "Happy new year 2018. Thanks for wathcing"; // Scrolling line


// just some reference flags
int stringStart, stringStop = 0;
int scrollCursor = screenWidth;

void setup()
{
  lcd.init();                      // initialize the lcd 
  
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Hello, world!");
  
  
}

void loop()
{
   
  lcd.setCursor(0, 0);
  lcd.print(line1);
  
  lcd.setCursor(scrollCursor, 1);
  lcd.print(line2.substring(stringStart,stringStop));
  
  delay(400);
  
  lcd.clear();
  
  if(stringStart == 0 && scrollCursor > 0){
    scrollCursor--;
    stringStop++;
  } else if (stringStart == stringStop){
    stringStart = stringStop = 0;
    scrollCursor = screenWidth;
  } else if (stringStop == line2.length() && scrollCursor == 0) {
    stringStart++;
  } else {
    stringStart++;
    stringStop++;
  }
  
}

ความคิดเห็น

  1. hello, your code is work. but all the text is blinking.to fix them, you can fix them by remove lcd.clear();

    thank you for your code.

    ตอบลบ
  2. Thank you so much. This helped me for a troublesome school project.

    ตอบลบ

แสดงความคิดเห็น