variables

I am having a problem getting variables to work as I intend.

I have declaring the variable a few different ways but can't get working results.

Here is what I have:

String LCD_line2 = " "; // Message for LCD line 2

// change it to this
LCD_line2 = "! OVER VOLTAGE !";

// print 2nd line of LCD
lcd.setCursor(0,1);
lcd.print(LCD_line2);

I am getting a number on the screen, 8225?

did you check if the .print function accepts "String" types? Maybe it only accepts char* and not String.

did not know that was an option...

There must be a way to print a variable to the LCD? :astonished:

Try this:

String LCD_line2 = "                ";             // Message for LCD line 2

// change it to this
   LCD_line2 = "! OVER VOLTAGE !";

// print 2nd line of LCD
  lcd.setCursor(0,1);
  lcd.print(LCD_line2.toCharArray());

The '.toCharArray()' method returns the pointer to the internal buffer as a 'char *'.
The '.getBytes()' method is similar but returns 'unsigned char *' instead.

That will not compile;

 error: no matching function for call to 'String::toCharArray()'

What is an unsigned char?

Great. The reference manual installed with Arduino 22 fails to mention that there are two arguments required. See: toCharArray() - Arduino Reference

String LCD_line2 = "                ";             // Message for LCD line 2

char buff[17];

// change it to this
   LCD_line2 = "! OVER VOLTAGE !";

// print 2nd line of LCD
  lcd.setCursor(0,1);
  lcd.print(LCD_line2.toCharArray(buff,sizeof buff));

Ok I got it working but i don't know exactly why.

I think it was going from 'value' to "value" :open_mouth:

lcd.print(lcd_line2); is now working