Serial.print goes forever

Hello:

So I’ve recently decided to write my own code. I’m an absolute beginner to arduino programming.

I’ve decided to control two LCDs at one time. In the Serial Monitor, I type in 1 or 2 to pick either LCD to print stuff in.

But the problem is it prints on and on forever, like this. By the way, the first lcd prints "Open serial and send to write"The Code is:

#include <LiquidCrystal.h>

LiquidCrystal one(12, 11, 10, 5, 4, 3, 2);
LiquidCrystal two(27, 29, 31, 33, 35, 37, 39);

void setup() {
Serial.begin(9600);
one.begin(2, 16);
one.clear();
one.setCursor(0, 0);
one.print(“Open serial and”);
one.setCursor(0, 1);
one.print(“Send to write”);
}

void loop() {
Serial.print (“Send the number 1 or 2 to select which lcd you want to print stuff on:”);
if (Serial.available())
{
char number = Serial.read();
if (number == ‘1’)
{
Serial.print (“Send something you want to print on screen 1:”);
delay (100);
one.clear();
while (Serial.available() > 0) {
one.write(Serial.read());
}
}
else if (number == ‘2’)
{
Serial.print (“Send something you want to print on screen 2:”);
delay (100);
two.clear();
while (Serial.available() > 0) {
// display each character to the LCD
two.write(Serial.read());
}
}
}
}

Untitled.tiff (115 KB)

It prints forever because you are not using a println only a print. The ln on the end of print stands for new line.

while (Serial.available() > 0) {
      one.write(Serial.read());

How many times do you think that loop is going to run for?

Grumpy_Mike: It prints forever because you are not using a println only a print. The ln on the end of print stands for new line.

I tried println but it just prints vertically forever.

You have to remember that the loop function repeats forever so any print statement in it will print forever. If this is not what you want then do not put a print statement where it will be execuited every time round the loop.

Grumpy_Mike: You have to remember that the loop function repeats forever so any print statement in it will print forever. If this is not what you want then do not put a print statement where it will be execuited every time round the loop.

OK I got it... Thanks everyone who helped!