Go Down

Topic: variables (Read 1 time) previous topic - next topic

2660

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:
Quote

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?

frank26080115

did you check if the .print function accepts "String" types? Maybe it only accepts char* and not String.
Freelance engineer, consultant, contractor. Graduated from UW in 2013.

2660

did not know that was an option...

2660

There must be a way to print a variable to the LCD?   :smiley-eek:



johnwasser

Try this:

Code: [Select]

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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

2660

That will not compile;
Code: [Select]
error: no matching function for call to 'String::toCharArray()'

What is an unsigned char?

johnwasser

Great.  The reference manual installed with Arduino 22 fails to mention that there are two arguments required.  See: http://arduino.cc/en/Reference/StringToCharArray

Code: [Select]

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));
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

2660

#7
Aug 08, 2011, 04:24 am Last Edit: Aug 08, 2011, 04:52 am by 2660 Reason: 1
Ok I got it working but i don't know exactly why.

I think it was going from 'value' to "value"   :smiley-surprise:

Code: [Select]
lcd.print(lcd_line2); is now working

Go Up