lcd.print or lcd.write, Both seem to do the same thing but when would you use one over the other
They do different things.
print() formats what is sent and then calls write()
write() sends raw data to the LCD.
If you wan't to display a char array string, call lcd.write(string), e.g. lcd.write("Hello!");. This is much more efficent than print as the print function does nothing to strings.
if you want to display a floating point number, you have to use lcd.print() as the write function cannot take a floating point argument. The print function creates a string which is a representation of the floating point number which is then sends to write().
If you want to display a single character, again, use write(character) as it is more efficient.
If you want to display an integer such as the result of millis(), you have to use lcd.print(). print() will create a string representation of the number. If you send it directly to write() you would see garbage for the reason below:
Take the number 10. There are two ways it could be displayed, either as a single character, or as a string of characters.
lcd.print(10); would result in two characters being displayed: "1" then "0". You would see that on the display as you want it to.
lcd.write(10); would result in one character being displayed, the ascii value 10. This is actually a newline character, so it is a non-visible character.
So in summary
print() converts any argument you send it to a string of ascii characters which are visible when they are displayed.
write() sends the raw argument value, which may or may not be a visible character.
Something to try:
Upload the following sketch:
void setup() {
int data = 55;
Serial.begin(9600);
Serial.print("Using Write: ");
Serial.write(data);
Serial.println();
Serial.print("Using Print: ");
Serial.print(data);
}
void loop() {
}
What do you see?
That's what I call an excellent explanation. Thank you I now understand.
karma awarded. 8)