In the code below you are checking for the state of the button rather than the change in state of the button (i.e., not pressed -> pressed). This in combination with the 5s delay in your code means that you have to hold the a button and release it at exactly the right time to cause an action to happen. Study the following tutorials:
StateChangeDetection
Example-code for timing based on millis()
BlinkWithoutDelay
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState2 = digitalRead(buttonPin3);
if (buttonState1 == HIGH) {
letter = letter + 1;
buttonState1 == LOW;
}
if (buttonState2 == HIGH) {
letter = letter - 1;
buttonState2 == LOW;
}
// lcd.setCursor(0, 0);
// lcd.setCursor(0,1);
// lcd.print(val);
if (buttonState3 == HIGH) {
print = true;
lcd.setCursor(0, 0);
lcd.print("A letter has been entered!");
}
The following code:
switch (letter) {
case 1:
lcd.print('a');
val = 'a';
break;
case 2:
lcd.print('b');
val = 'b';
break;
.
.
.
case 26:
lcd.print('z');
val = 'z';
break;
}
can be replaced by:
val = 'a' + letter;
lcd.print(val);