Hi. I am about to create a display that is supposed to display two different pieces of information using a button. That is, pressing (and releasing) the button changes the text to the other. I have already started the work but I have a problem because the button seems not to work. I don't know if the problem is in the program or the connection. I am inserting the code and how I connected the button( instead of arduino it is esp32)
.
Connection: https://www.arduino.cc/en/uploads/Tutorial/button.png
#include <LiquidCrystal_I2C.h>
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
int buttonpin = 12;
int buttonState = 0;
void setup()
{
lcd.init();
// turn on LCD backlight
lcd.backlight();
pinMode(buttonpin, INPUT_PULLUP);
}
void loop() {
buttonState = digitalRead(buttonpin);
if (buttonState == LOW) {
lcd.setCursor(0, 0);
// print message
lcd.print("Hello, World!");
delay(1000);
// clears the display to print new message
lcd.clear();
}
else {
lcd.setCursor(0, 1);
// print message
lcd.print("Home, come!");
delay(1000);
// clears the display to print new message
lcd.clear();
}
}
Connection: https://www.arduino.cc/en/uploads/Tutorial/button.png