I'll post them each in their own code box, the attachment feature is a bit ackward. My display is a LCM-S04004DSF and uses an Arduino Due. Each block is a complete program and should be duplicable if you adjust the pin numbers.
This version works correctly, and displays the text on the second line of the display.
#include <LiquidCrystal.h>
LiquidCrystal lcd(28, 26, 25, 24, 23, 22);
void setup() {
lcd.begin(40, 2);
lcd.clear();
lcd.display();
lcd.setCursor(0, 1);
lcd.print("Test");
}
void loop() {
}
This version works incorrectly, and displays the text on the first line of the display because for some reason _lcd.setCursor(0, 1) did not actually move the cursor. But it's clearly doing something because the text still appears, so one function works but the other doesn't.
#include <LiquidCrystal.h>
class mouse {
private:
LiquidCrystal _lcd;
public:
mouse(LiquidCrystal &lcd) : _lcd(lcd) {};
void writeTest(void) {
_lcd.setCursor(0, 1);
_lcd.print("Test");
};
};
LiquidCrystal lcd(28, 26, 25, 24, 23, 22);
mouse myMouse(lcd);
void setup() {
lcd.begin(40, 2);
lcd.clear();
lcd.display();
myMouse.writeTest();
}
void loop() {
}
But this version works fine again. All I've done is pass it using a pointer instead of a reference, swapping _lcd.setCursor for _lcd->setCursor, so my understanding is that these are completely identical. Yet for some reason they are not.
#include <LiquidCrystal.h>
class mouse {
private:
LiquidCrystal* _lcd;
public:
mouse(LiquidCrystal* lcd) : _lcd(lcd) {};
void writeTest(void) {
_lcd->setCursor(0, 1);
_lcd->print("Test");
};
};
LiquidCrystal lcd(28, 26, 25, 24, 23, 22);
mouse myMouse(&lcd);
void setup() {
lcd.begin(40, 2);
lcd.clear();
lcd.display();
myMouse.writeTest();
}
void loop() {
}