I have a project split into several files:
//Loop.cpp
#include "LiquidCrystal.h"
void setup(){
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
lcd.begin(16, 2);
}
void loop() {
//Code
}
//Display.cpp
#include "LiquidCrystal.h"
namespace display {
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void displayData(const InputPacket &inputPacket, const DataPacket &dataPacket) {
lcd.setCursor(0,1);
lcd.print("Foo"); //This creates display error, unless i call lcd.begin(16, 2) in this function
}
} //namespace display
My initial problem is that - without calling lcd.begin() from within displayData() - the characters aren't displayed correctly. In other words, calling lcd.begin() in setup() doesn't help. (It appears to me that setup() has implicit static property, no?)
As an attempted solution, i could create an lcd object in Display.cpp, and call lcd.begin() from within displayData(). Even though characters are displayed properly, this gives me display flickering. (Presumably as a result of calling these functions repeatedly in the loop during runtime).
So, the only solution to this dilemma that i can come up with is to call lcd.begin() from a function written to run only once inside of displayData(). Or is it?
My question is, are there other more elegant solutions/alternatives?