#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 //Define the reset pin of the OLED as same as the reset pin of the ESP32.
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
// Initialize seriel monitor and OLED display.
Serial.begin(115200);
if (! display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) // Here we check, was the display initialize successfully? "!" symbol works as logical not operation.
{
Serial.println(F("SSD1306 allocation failed")); // If the display was not initialize successfully, above ! statement will become true and this line will be print.
for (;;); // This is an infinitely executing for loop without any inputs. the code will not be run beyond this for loop if the display is not working.
}
// Turn o OLED display.
display.display();
delay(2000);
// Clear OLED display.
display.clearDisplay();
// Display a custom message.
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println(F("Welcome to Medibox !"));
display.display();
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}