Pages: [1]   Go Down
Author Topic: variables  (Read 1112 times)
0 Members and 1 Guest are viewing this topic.
The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Freelance engineer, consultant, contractor. Graduated from UW in 2013.

The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

did not know that was an option...
Logged

The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 179
Posts: 8074
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this:

Code:
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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

What is an unsigned char?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 179
Posts: 8074
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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));
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

The people's republic of Massachusetts
Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Code:
lcd.print(lcd_line2);
is now working
« Last Edit: August 07, 2011, 09:52:37 pm by 02660 » Logged

Pages: [1]   Go Up
Jump to: