16x02 LCD Display to show a variable

Hi all, I am looking for my LCD display 16x02 to print a variable from my code (the amount of times a push button is pressed).

The push button counter variable is fine, it is counting and being printed to the serial port as it should be. However I want to use an LCD display rather than the serial port in final implementation.

At the moment I have the code attached which prints the following to the LCD display.

Qty = 000/999
Length (mm): XXX

I want my FIRST variable which is called (QtyPushCounter) to be printed where the 000 is.
And my SECOND variable which is called (LengthPushCounter) to be printed where the XXX is.

Could someone point me in the right direction? Apologies if this question has been asked before, but I couldnt find a specific example.

// set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Qty: 000/999 ");
 // (millis(),150);
  lcd.setCursor(0,1);
  lcd.print("Length (mm): ");

I assumed it would be something like;

// set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Qty: (QtyPushCounter)/999 ");
 // (millis(),150);
  lcd.setCursor(0,1);
  lcd.print("Length (mm): (LengthPushCounter) ");

But this won't compile due to the bracketing system.

Thanks in advance, to any input. Much appreciated!

Maybe:

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

  // Print a message to the LCD.
  lcd.clear();           
  lcd.print("Qty: ");  
  lcd.print(QtyPushCounter);
  lcd.print("/999 ");
 // (millis(),150);
  lcd.setCursor(0,1);
  lcd.print("Length (mm): ");
  lcd.print(LengthPushCounter);

lcd.begin should be in setup() as it only needs to be called once.

I will give that a whirl, and see the results. Thank you for your time.

Will let you know how I get on.

What the other guy posted should work, i had the same problem first time using the lcd, as i was trying to do too much for each print function. When printing like...lcd.print("..."), think of that as a fixed value that wont change. so for the line after that you can write...lcd.print(val). and then if you want the units for example temperature, you could then write lcd.print("C").

Beginner Arduino Project - DHT11 with LCD (I2C) - YouTube - a link to my video with an lcd, the example code in the description shows this function.

Thanks GroundFungus and JonBoy,

Managed to achieve the results I was after using your methods, final code looked like this for anyone who is interested.

     lcd.clear();                              //clears whatever is on the display
     lcd.setCursor(0,0);                   // sets the cursor to the first row, first line of the 16x02 screen
     lcd.print("Qty = 000/");             // prints the word Statement Qty = 000/
     lcd.print(QtyPushCounter);        // prints the value of the variable called QtyPushCounter

     lcd.setCursor(0,1);                  // sets the cursor to the first row, second line of the 16x02 screen
     lcd.print("Length = ");             // prints the word Statement Length = 
     lcd.print(LengthPushCounter);   // prints the value of the variable called LengthPushCounter
     lcd.print("mm");                     // prints the word Statement mm

The idea being, that whenever the variable counters for the qty counter or length counter change in value the value is printed to the lcd display.

so the lcd display looks like this;

Qty = 000/ (qtycounter value)
Length = (length counter value) mm