Hi, I have uploaded the code below to my Arduino UNO that is hooked up to a 16 x 2 LCD, and I am having trouble with the input for the last name. My code allows the user to input their first name and last name to be displayed on both rows of the LCD (first name on top, last name on bottom). However, when I input the last name, only one character shows up; on the other hand, the first name displays correctly. For example, if I input "John" as the first name and "Doe" as the last name, "John" would appear on the top, and "e" would appear on the bottom. I tried debugging it with some Serial.print() statements, and it shows that the last name is being printed. I am not sure what to do now, and any help would be greatly appreciated because I have a school deadline coming up.
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int choice = 1;
int stopper = 0;
int stopper2 = 0;
int x = 1;
int y = 1;void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
lcd.print("Welcome to your");
lcd.setCursor(0,1);
lcd.print("personal LCD!");
delay(4000);
lcd.clear();
lcd.print("Please type your");
lcd.setCursor(0,1);
lcd.print("name on the");
delay(2500);
lcd.clear();
lcd.print("serial monitor");}
void loop()
{switch (choice) {
case 1:
if (Serial.available()){
delay(100);
lcd.clear();while (Serial.available() > 0) {
char name = Serial.read();
Serial.print(name);
lcd.print(name);}
choice = 2;
}
break;case 2:
if (y == 1) {
lcd.setCursor(0,1);
lcd.print("Type last name");
}
y = 2;
if (Serial.available()){
delay(100);
lcd.setCursor(0,1);
lcd.print(" ");
while (Serial.available() > 0) {
char name2 = Serial.read();
lcd.setCursor(0, 1);
Serial.print(name2);
lcd.print(name2);
}
choice = 3;
}break;
default:
if (x == 1) {
Serial.println("Good Job, you've written your name!");
}
x = 2;
break;}
}