The problem I have with LCD l2c screen when connected to an arduino and a button is that when the screen is connected to pin 13 and I run the code. I press the button and nothing happends... I change pin 13 to pin 5V and press the button it shows "PRESSED" and i change back to pin 13 then it turn on and off the screen but no text is displayed.
I think it is some voltage problem but i do not know what to change. This is how it is connected now.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27
const int buttonPin = A1;
int lastButtonState;
void testButton() {
int currentButtonState = digitalRead(buttonPin);
if ((currentButtonState == LOW) && (lastButtonState == HIGH)) {
digitalWrite(LED_BUILTIN, HIGH);
lcd.print(F("PRESSED"));
delay(15); // poor's man anti-bounce
} else if ((currentButtonState == HIGH) && (lastButtonState == LOW)) {
digitalWrite(LED_BUILTIN, LOW);
delay(15); // poor's man anti-bounce
}
lastButtonState = currentButtonState;
}
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
// initialize the lcd
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lastButtonState = digitalRead(buttonPin);
}
void loop() {
testButton();
}