// Include libraries
#include <Wire.h> // For I2C communication (included in ESp32 by default)
#include <Adafruit_GFX.h> // Provides functions for drawing graphics and text on the display
#include <Adafruit_SSD1306.h> // Handles communication and control of the SSD1306 OLED display driver chip
// Define OLED parameters
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Set it to -1 if your module doesn't have a separate reset pin and shares the reset pin with the ESP32.
#define SCREEN_ADDRESS 0x3C // I2C address of your OLED display (Some have 0x3D)
// This line creates an instance named display, of the class Adafruit_SSD1306, which will be used to control the OLED display.
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup(){
Serial.begin(115200);
// SSD1306_SWITCHCAPVCC, tells the library to use the ESP32's internal 3.3V supply to generate the necessary voltage for the display
// If the initialization fails, an error message is printed, and the code enters an infinite loop.
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)){ // (! = not)
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Infinite loop (To stop the program from proceeding further)
}
display.display(); // Shows initial display buffer contents on the screen (Adafruit boot screen)
delay(2000); // Pause for 2 seconds
display.clearDisplay(); // Clears the buffer
display.setTextSize(1); // Normal text size (1:1 pixel scale)
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0); // (column, row) Sets the cursor position to the top-left corner
display.println(F("Welcome to Medibox!")); // The F macro tells the compiler to store a string directly in flash memory (program memory) instead of RAM. Hence load on RAM is reduced.
display.display();
}
void loop(){
delay(10); // this speeds up the simulation
// Simulation environments often run at an accelerated pace compared to real-time hardware.
// This means that the code executes and updates the simulated display much faster than it would on an actual physical device.
// By introducing a small delay, the code execution slows down slightly within the simulation.
// This allows the simulated OLED display to catch up and update at a more observable rate, making it easier to see the changes happening on the display.
}