Go Down

Topic: display the analogRead to lcd screen (Read 749 times) previous topic - next topic

latif

Mar 03, 2011, 10:36 am Last Edit: Mar 03, 2011, 10:45 am by latif Reason: 1
what i need to do is write in the screen:
Value 1 = (the reading from sensor)

my code is:
 sensorValue = analogRead(sensorOne);      // read sensorOne value.
 lcd.setCursor(0, 1)
 Serial.print("Sensor One = "sensorValue, DEC);


does this look right!?!

mowcius

Nope.

More like:
Code: [Select]

  sensorValue = analogRead(sensorOne);      // read sensorOne value.
  lcd.setCursor(0, 1)
  lcd.print("Sensor One = ");
  lcd.print(sensorOne);

liudr


what i need to do is write in the screen:
Value 1 = (the reading from sensor)

my code is:
 sensorValue = analogRead(sensorOne);      // read sensorOne value.
 lcd.setCursor(0, 1)
 Serial.print("Sensor One = "sensorValue, DEC);


does this look right!?!

The above won't work. You should use the code posted by mowcius.
If you want this to work, you could look into the sprintf on cplusplus.com. The sprintf gives you more handle on how many digits you print before and after the decimal point and what not. I do this:

char msg[20];
sprintf(msg,"value=%04d", sensorValue);
Serial.print(msg);

This way also saves you program size if you will need to use the sprinft for other outputs in your program anyway. You save from not having to compile the overloaded Serial.print(int,int)

BTW, didn't you mean lcd.print instead of Serial.print?  8)

Go Up