having trouble with lcd.setCursor(0,1);

Hi im working on a project about a morse code translator.

Process

  1. You type on the serial monitor what you want to translate
  2. The LCD will display it

Now the problem is...if I type in a sentence that is too long.... I will send a picture so you guys can understand better. The picture shows "my name is edgar" displayed in the lcd. I typed in the serial monitor "my name is edgar steven olazo"

So may question is..how can I display it in the serial monitor like this:

my name is edgar
steven olazo

here is the code

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, NEGATIVE);

#define I2C_ADDR 0x27  // Define the address of the serial communication display 
#define LED_OFF 0
#define LED_ON 1


#define debug true

int ledPin = 13;          //The pin, your LED is connected to.
int speakerPin = 9;       //The pin, your buzzer or speaker is connected to.
int pitch1 = 140;      
int pitch2 = 140;
int dot = 50;         
int dash = 3 * dot;    


String morseATable[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.",   // A-G
                        "....", "..", ".---", "_._", ".-..", "--", "-.",    // H-N
                        "---", ".--.", "--.-", ".-.", "...", "-", "..-",    // O-U
                        "...-", ".--", "-..-", "-.--", "--.."               // V-Z
                      };


String morseNTable[] = { "-----", ".----", "..---", "...--", "....-",       // 0-4
                        ".....", "-....", "--...", "---..", "----."         // 5-9
                      };

                     
void setup()
{
  lcd.begin(16, 2);              //Initialize the display
  lcd.setBacklight(LED_OFF);
  lcd.cursor();
  pinMode(ledPin, OUTPUT);                    
  pinMode(speakerPin, OUTPUT);          
  Serial.begin(9600);                      
  if (debug)
    Serial.println("\nSTART");                
    
}

void loop ()
{
     if(true){
      
convert2Morse(Serial.readString());     
     }
  
} 
void convert2Morse(String message)
{
  for (int pos = 0; pos < message.length(); pos++)
    { 
      if (debug) 
        {
          Serial.print(message.charAt(pos));
          Serial.print("   ");
          lcd.print(message.charAt(pos));
         
         
        }
      if ((message.charAt(pos) >= 97) && (message.charAt(pos) <= 122))    
        morseLED(morseATable[message.charAt(pos)-97]);
      if ((message.charAt(pos) >= 48) && (message.charAt(pos) <= 57))     
        morseLED(morseNTable[message[pos]-48]);  
      if (message.charAt(pos) == 32)                                   
        morseLED("       ");                                         
      if (debug)
        Serial.println();
      
   

    }


delay(5000);
lcd.clear();


}



void morseLED(String sequence)
{  
  for (int pos = 0; pos < sequence.length(); pos++)
    flashLED(sequence.charAt(pos));
  delay(2 * dot);                                                            
}

void flashLED(char dotOrDash)
{
  if (debug)
    Serial.print(dotOrDash);
   
   
  if (dotOrDash == 46)             
    {
      digitalWrite(ledPin, HIGH); 
      tone (speakerPin, pitch1);
      delay(dot);                   
      digitalWrite(ledPin, LOW);   
      noTone(speakerPin); 
      delay(dot);
    }
  else
    if (dotOrDash == 45)
      {                               
        digitalWrite(ledPin, HIGH);  
        tone (speakerPin, pitch2);
        delay(dash);                 
        digitalWrite(ledPin, LOW);   
        noTone(speakerPin); 
        delay(dot);
      }
    else
      if (dotOrDash == 32)            
        delay(dot);                   
}

It isn't clear what you are wanting.
You said you typed in a long line and showed how it displayed on the LCD and then asked:

So may question is..how can I display it in the serial monitor like this:

my name is edgar
steven olazo

Which is asking how to change the output on the Serial monitor.
So I can't tell if you are wanting to change the Serial output or the LCD display output.

Wrapping long lines is easy, breaking a string and wrapping a line so that characters in words don't wrap across lines is much more difficult.

If all you need to do is wrap long lines on the LCD then you could switch to my hd44780 library.
It is available in the IDE library manager - use the hd44780_I2Cexp i/o class. More here:

You can control line wrapping on the LCD using lineWrap() and noLineWrap()
While that will wrap lines, it won't wrap on word boundaries. That is more difficult and would have to be done in your sketch code as the LCD library can't do it since it can only see 1 character at a time so can not see the entire string.

--- bill

BTW, the argument to setBacklight(dimlevel) is actually a dim level not an on/off, 0/1, true/false value.
A dimlevel of 1 means make the backlight as dim as possible without being off, while zero means off.
But If you don't need dimming, then it is better to use backlight() and noBacklight() for backlight control.

--- bill