Go Down

Topic: I2C LCD 16x2 Scroll Rows with joystick (Read 209 times) previous topic - next topic

Panda22

Dec 29, 2017, 11:25 pm Last Edit: Dec 29, 2017, 11:36 pm by Panda22
Today I was experimenting with my starter kit and I thinked how I can scroll text row by row on my I2C lcd 16x02 screen with a joystick and 4 hours later I finished the code.
Joystick x axis is conected to A0.
Code: [Select]
// This is Joystick and lcd example, this scroll rows
//Free modification
#define axisx analogRead(A0)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

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

int pn = 0;
#define p1 "Lorem ipsum"
#define p2 "dolor sit amet,"
#define p3 "consectetur"
#define p4  "adipiscing elit"
#define p5  "posuere"
void setup()
{
  // initialize the LCD
  lcd.begin();
  lcd.print("Lorem ipsum");
  lcd.setCursor(0, 1);
  lcd.print("dolor sit amet,");

}
void loop() {
  int nv = 1;//declare the integrer 1
  if (axisx >= 530  && nv == 1) {//Goes down
    if (pn == 0  && nv == 1) {
      lcd.clear();
      lcd.print(p2);
      lcd.setCursor(0, 1);
      lcd.print(p3);
      pn = 1;
      nv = 0;
    }
    if (pn == 1  && nv == 1) {
      lcd.clear();
      lcd.print(p3);
      lcd.setCursor(0, 1);
      lcd.print(p4);
      pn = 2;
      nv = 0;
    }
    if (pn == 2  && nv == 1) {
      lcd.clear();
      lcd.print(p4);
      lcd.setCursor(0, 1);
      lcd.print(p5);
      pn = 3;
      nv = 0;
    }
   
  }
  if (axisx <= 510  && nv == 1) {//Goes up
    if (pn == 1  && nv == 1) {
      lcd.clear();
      lcd.print(p1);
      lcd.setCursor(0, 1);
      lcd.print(p2);
      pn = 0;
      nv = 0;
    }
    if (pn == 2  && nv == 1) {
      lcd.clear();
      lcd.print(p2);
      lcd.setCursor(0, 1);
      lcd.print(p3);
      pn = 1;
      nv = 0;
    }
    if (pn == 3  && nv == 1) {
      lcd.clear();
      lcd.print(p3);
      lcd.setCursor(0, 1);
      lcd.print(p4);
      pn = 2;
      nv = 0;
    }
    }
  delay(2500);
}

Go Up