LCD 16x2 change messages with button to ground

Hi everyone, before posting this request I searched for a long time on the web but despite the fact that I believe mine is a simple requirement I have not found answers.

In practice I need to create a simple circuit where by pressing a key (connected to ground) I can change a message on the second line of the display (the text of the first must remain the same)
for example if I press the 1 key the display will show "text 1", if I press the two key "text 2" and so on for a total of 5 keys.

you will surely understand that I am absolutely at the beginning and wondered if any of you knew about scketch that I could modify for this basic project.

Set the switch pins pinModes to INPUT_PULLUP. Then the switches will read HIGH when not pressed and LOW when pressed. Adjust the logic in the program to expect LOW on pressed.

And a few hints about working with the forum here:

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code" it can easily become quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.

#include <LiquidCrystal.h>
 

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
 
const int buttonPin = A1; 
const int buttonPin2 = A2; 
const int buttonPin3 = A3;     
const int buttonPin4 = A4;
const int buttonPin5 = A5;
 

const int ledPin =  4;     
const int ledPin2 =  5;     
const int ledPin3 =  6;     
 

int buttonState = 0;   
int buttonState2 = 0;       
int buttonState3 = 0; 
int buttonState4 = 0;   
int buttonState5 = 0;         
 

int buzzer = 3;     //buzzer connesso al pin 3
 
void setup() {

  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(buzzer,OUTPUT);
 

  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);
  pinMode(buttonPin2, INPUT);
  digitalWrite(buttonPin2, HIGH);
  pinMode(buttonPin3, INPUT);
  digitalWrite(buttonPin3, HIGH);
 
  lcd.begin(16, 2);

  lcd.print("007 TRIBUTE ED.");
  lcd.setCursor(0, 1);
  lcd.print("Stand by");

  digitalWrite(ledPin, 00);
}
 
void loop() {
 
  buttonState = digitalRead(buttonPin);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
 
  // Se il primo bottone viene schiacciato
  if (buttonState == 0) {
    // Ripulisci lo schermo da altre eventuali scritte
    lcd.clear();
    // Scrivo nella prima riga "Riga 0" e nella seconda "Riga sotto 0"
    lcd.print("1row");
    lcd.setCursor(0, 1);
    lcd.print("2 row");
   

    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    // suona la nota sul buzzer
    tone(buzzer,3000,200);
    delay(500);
  } else {
  if (buttonState2 == 0) {
    lcd.clear();
    lcd.print("1 row");
    lcd.setCursor(0, 1);
    lcd.print("2 row");
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin3, LOW);
    tone(buzzer,3000,200);     
    delay(500);
 

  } else {
  if (buttonState3 == 0) {
    lcd.clear();
    lcd.print("3 row");
    lcd.setCursor(0, 1);
    lcd.print("3 row");
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    tone(buzzer,3000,200);
    delay(500);

    
  } else {
  if (buttonState4 == 0) {
    lcd.clear();
    lcd.print("4 row");
    lcd.setCursor(0, 1);
    lcd.print("4 row");
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    tone(buzzer,3000,200);
    delay(500);

  } else {
  if (buttonState5 == 0) {
    lcd.clear();
    lcd.print("5 row");
    lcd.setCursor(0, 1);
    lcd.print("5 row");
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
    tone(buzzer,3000,200);
    delay(500);
}
}

sorry for my posting mistake,with your suggestion i have done this sketch but i get "expected } at end of input", where is the error?

thanks

Hi.

That message is the white text in the orange bar.
Below that, there's much more orange text in a black box (you can scroll through the text).
It says this:

sketch_filename.ino:124:1: error: expected '}' at end of input

The 124:1 is a big help to you.
It shows where the error is; on line 124 and on the second position (first position would be 0).
That's where the next } was expected to be, but for clarity to yourself you would put that on a new line.

Whenever there's a { in your sketch, there has to be an accompanying } to it.
You're missing (at least) one of those.
The { } are a very important part of your sketch, and everybody has made mistakes with them at some time.
That's why the IDE can help you finding these sets of curly braces.
Put your cursor at the right of a { or } of which you want to find it's partner } or {.
The IDE will put a small blue box around the partner } or {, so it'll be easy for you to identify it.
If there's no blue box to be found, the curly brace you've put your cursor next to, is missing it's partner.

Also, you should hit ctrl-t (on a Windows system) before copying and posting to this forum, that's also in the instructions you recently (partially) read.
It'll be a great help to you and to people you're asking help from, as the IDE creates correct indents to your sketch-text.

Try these two tips and use them.
You'll appreciate them once you got to know how to use them.

Didn't follow my instructions - to correct post #1.

MAS3:
Also, you should hit ctrl-t (on a Windows system) before copying and posting to this forum, that's also in the instructions you recently (partially) read.

What does Windoze have to do with it? :astonished:

At some time i read that there's some other key to hit on non Windows systems, together with the T key.
I don't know, because i use windows.
Because that's my reference, i know that that works as described.
Perhaps Linux (using the same hardware) uses the same combination, but does an Apple system even have a ctrl-key ?
I really don't know and am not really interested in it either.
So if a person reading this has a system that doesn't have such key, they should find out for themselves what equivalent keystrokes would be needed to get the autoformat.
Or look for it in IDE's menu bar.

Let me assure you that Linux uses the same interface as Windoze. :grinning:

Apple keyboard?

If you are a beginner, you can get started by combining two tutorials for beginners: