My 128x64 display works OK. Now I would like to detect that the display ( or e.g. SDA cable) is disconnected. I thought I would achieve that by checking return bool from ::begin ().
However, the code below returns always 'true' (even when SDA not connected)
"No status read is provided for serial mode" --> there is no way to read information back from the display in serial mode, as the read status register is the only command that would allow it. And you use serial mode. ergo: out of luck.
I have a Lilygo ESP32 T-Beam, that normally has an OLED display connected.
I have a socket on the back of the T-Beam case where I can plug in an I2C backpack 20x4 LCD, which is visible in direct sunlight whereas the OLED is not.
The software automatically detects if the I2C backpack 20x4 LCD, on address 0x3F, is connected and if it is uses that display, here is the code;
I see there are functions Adafruit_SSD1306::drawPixel () and getPixel (). Maybe this pair could be used to see if pixel is set or not ? Or is the display frame buffer in Adruino MCU memory ?
Interesting point. My understanding is 'it is called when variable is allocated on the stack and initialized'. Here, before if () is called.
But then what about this. I think okoCC is allocated on the stack before if() is executed as well. And therefore initialised before if () ? No idea. Must be defined somewhere in C++ standard what sequencing is used here.
bool InitialiseDisplay ()
{
bool oko { gDisplay.begin ( SSD1306_SWITCHCAPVCC, SCScreenAddress ) };
if ( true == oko )
{
Serial.println ( "All good." );
oko = false;
}
const bool okoCC { oko }; // is there a guarantee okoCC to be always 'false' ?
return oko;
}