Arduino NANO Project

//*****************************************************
//F U N C T I O N S
void lcdDisplay()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Counter = ");
lcd.print(CounterValue);
lcd.setCursor(0,1);
lcd.print("Time = ");
lcd.print(millis());
}
// E N D O F C O D E
//***********************************************************
this is for counter display and timer display

YES

You are doing well :wink:

OK,

Thanks

Respectable clarification :slight_smile:

I try to understand LCD display location.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

lcd.begin(16, 2);
}

void loop() {

lcd.setCursor(0, 0);

lcd.print("1");

lcd.setCursor(2, 0);

lcd.print("2");
lcd.setCursor(4, 0);

lcd.print("3");
lcd.setCursor(6, 0);

lcd.print("4");
lcd.setCursor(8, 0);

lcd.print("5");
lcd.setCursor(10, 0);

lcd.print("6");
lcd.setCursor(12, 0);

lcd.print("7");
lcd.setCursor(14, 0);

lcd.print("8");
lcd.setCursor(16, 0);

//------------------

lcd.setCursor(0, 1);

lcd.print("A");
lcd.setCursor(2, 1);

lcd.print("B");
lcd.setCursor(4, 1);

lcd.print("C");
lcd.setCursor(6, 1);

lcd.print("D");
lcd.setCursor(8, 1);

lcd.print("E");
lcd.setCursor(10, 1);

lcd.print("F");
lcd.setCursor(12, 1);

lcd.print("G");
lcd.setCursor(14, 1);

lcd.print("H");
lcd.setCursor(16, 1);

}

LCD.jpg

BTW
This is a book that you might want to look at.

When you post you code, you really should use code tags.
Attach your code using the </> icon on the left side of the posting menu.
Put your sketch between the code tags [code][/code]

cf7aba6ee5e1c227a0dfc1bc6a97530690a80a54.jpg

16X2 ------> 0-15 = 16 locations 0-1 = 2 rows

#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
 
  lcd.begin(16, 2);
  }

void loop() {
  
 
  lcd.setCursor(0, 0);
  
  lcd.print("1");

  lcd.setCursor(2, 0);
  
  lcd.print("2");
  lcd.setCursor(4, 0);
  
  lcd.print("3");
  lcd.setCursor(6, 0);
  
  lcd.print("4");
  lcd.setCursor(8, 0);
  
  lcd.print("5");
  lcd.setCursor(10, 0);
  
  lcd.print("6");
  lcd.setCursor(12, 0);
  
  lcd.print("7");
  lcd.setCursor(14, 0);
  
  lcd.print("8");
  lcd.setCursor(16, 0);
  
 //------------------
 
  lcd.setCursor(0, 1);
  
  lcd.print("A");
  lcd.setCursor(2, 1);
  
  lcd.print("B");
  lcd.setCursor(4, 1);
  
  lcd.print("C");
  lcd.setCursor(6, 1);
  
  lcd.print("D");
  lcd.setCursor(8, 1);
  
  lcd.print("E");
  lcd.setCursor(10, 1);
  
  lcd.print("F");
  lcd.setCursor(12, 1);
  
  lcd.print("G");
  lcd.setCursor(14, 1);
  
  lcd.print("H");
  lcd.setCursor(16, 1);
   
}

ok

 Test

0,0 is top left hand side.
15,0 is top right hand side.

0,1 is bottom left hand side.
15,1 is bottom right hand side.

Test
G o o d

Test question

I have a 20X4 LCD.

Where is 19,3 ?

bottom right hand side.

:wink: :grinning:

How to Make LCD Scrolling Display?

Try:

//Sketch_01

// Use:  CTRL T    to format your code every now and then

#include <LiquidCrystal.h> //include the LCD library in this Sketch


//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//**********************************************************************
void setup() 
{
  //set up the LCD's number of columns and rows:
  lcd.begin(16, 2); 

  // Print a message to the LCD.
  lcd.clear(); //clear the LCD screen and go to location 0,0
  //0,0 is the first character on the first line on the LCD

} //  >>>>>>>>>>>>>> E N D  O F  s e t u p ( ) <<<<<<<<<<<<<<<<<

//**********************************************************************
void loop() 
{
  for(byte y = 0; y < 2; y++)
  {
    for(byte x = 0; x < 16; x++)
    {
      lcd.setCursor(x,y);      
      lcd.print(char('A'+ x));    
    }
  }
  while(1);

}


//======================================================================
//                      E N D  O F  C O D E
//======================================================================

How to Make LCD Scrolling Display?
That needs an 'array' that contains your message.
You print the message to the LCD wait some time, then read the array one character to the right, then print it again.
Then repeat.

Not scrolling

No that example was written before you asked about scrolling.

//Scrolling text

// Use:  CTRL T    to format your code every now and then

#include <LiquidCrystal.h> //include the LCD library in this Sketch

//char myArray[] = "Now is the time.";
char myArray[] = "                For this reason you should be careful in accessing arrays. Accessing past the end of an array (using an index number greater than your declared array size - 1) is reading from memory that is in use for other purposes. XXXX";

//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte x;

//**********************************************************************
void setup() 
{
  //set up the LCD's number of columns and rows:
  lcd.begin(16, 2); 

  // Print a message to the LCD.
  lcd.clear(); //clear the LCD screen and go to location 0,0
  //0,0 is the first character on the first line on the LCD

} //  >>>>>>>>>>>>>> E N D  O F  s e t u p ( ) <<<<<<<<<<<<<<<<<

//**********************************************************************
void loop() 
{
  static int y;
  for( x = 0 ; x < 16; x++)
  {
    lcd.setCursor(x,0);      
    lcd.print(myArray[x + y]);   
  }

  if(myArray[x + y+1] == '\0')
  {
    y = 0; // restart things.
    x = 0;
  }
  else
  {
    y = y + 1;
  }


  delay(300);
}


//======================================================================
//                      E N D  O F  C O D E
//======================================================================

Edit:
Updated code

Edit
There is a method where you put the array in program memory so you save on SRAM.
But that's another topic.

Yes,

It is working,

But

Don't under stand loop

void loop() 
{
  static int y;
  for( x = 0 ; x < 16; x++)
  {
    lcd.setCursor(x,0);      
    lcd.print(myArray[x + y]);   
  }

  if(myArray[x + y+1] == '\0')
  {
    y = 0; // restart things.
    x = 0;
  }
  else
  {
    y = y + 1;
  }


  delay(300);
}

Note: this can be hard to understand.

There are quite a few example sketches which are included in the IDE.
You should go through each sketch so you become familiar with C++ programming.

The book 'Arduino Cook Book' is a good reference.
There are lots of other books on the Arduino available.

//We have an array:
//           00000000000000000000000000000000000000000000000000000 . . . 2222222222  2
//           00000000001111111111222222222233333333334444444444555 . . . 3333333333  4
//           01234567890123456789012345678901234567890123456789012 . . . 0123456789  0                    
myArray[] = "                For this reason you should be careful . . . oses. XXXX" nul
//NOTE location 0-15 are all 'spaces'.  
//The last position in the myArray[] there is a 'nul' which is equal to the character '\0'
//The '\0' is put there for you.   

//This line says make a function called loop(). 
//This will be a 'void' function which returns NO value when loop() is finished.  
void loop() 
{ //Start of the function loop()
  static int y = 0; //This makes a variable 'y'. It is an integer. At the beginning make y = 0
                    //'static' means remember what the value of 'y' is when loop() is finished.  
  
  //****************************
  //Here we are creating an internal loop. This is called a 'for loop'. 
  //We will circulate 16 times between the { and } braces.   i.e. 0-15
  //Each time through this 'for loop' we add 1 to x
  //Therefore x will take on 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15  which is 16 different values.
  //The last time in the loop, x = 16 so we leave this  'for loop'
  for( x = 0; x < 16; x++)
  {
    //In 'total' we set the position to 0,0  1,0  2,0  3,0 . . . 15,0   16,0 where we fall out of the 'for loop'
    lcd.setCursor(x,0);
    //The first time through the 'for loop' y = 0, therefore x + y = 0, location 0 in myArray
    //Location = 0 in the array is a 'space'. So are 'locations' 1-15 spaces. (Location 16 = F, 17 = o 18 = r etc. as in 'For' )
    //Therefore we will print a space at location 0,0  
    lcd.print(myArray[x + y]); // x is the location in the next 16 characters and y is an offset into the array
    //At this point we jump back to the line for( x = 0; x < 16; x++)
    //Here we add 1 to x so if x was 0 it becomes 1 etc. This happens 16 times in total.
  }
  //****************************
  
  //We have just fallen out of the 'for loop' at this point.  
  
  //We ask if we have arrived at the end of myArray[] where there is the 'nul'  '\0'
  if(myArray[x + y + 1] == '\0') 
  {
    //If the last character is detected, we make y = 0 so we can point back to the beginning of myArray again.
    y = 0; // reinitialize to the beginning.
    //x = 0; // this line is not needed
  }
  else
  {
     //We are not at the end of myArray[].
     //We increment y (the offset).
     //When we reach the last } in loop(), we go back to the first { in loop() where we will
     //be reading the next group of 16 characters in the array.
    y = y + 1;
  }

  //We wait here for a short time 3/10 second so we can read the LCD
  delay(300);
  
} //Finish of the loop() function, we now go back to the first { in loop()

EDIT:
Code updated

LarryD, you have the patience of a saint.