// // for requesting time
// #include <WiFi.h>
// #include <time.h>
// for the display
// for the display
#include <Wire.h> //wire library responsible for the I2C communication
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// for the display
#define SCREEN_WIDTH 128 //OLED display width in pixels
#define SCREEN_HEIGHT 64 //OLED dispaly height in pixels
#define OLED_RESET -1 //reset pin for the display is same as the esp32 board
#define SCREEN_ADDRESS 0x3C //see datasheet for the adddress //this is I3C address of the OLED display
// // for requesting time
// const char* ssid = "Wokwi-GUEST";
// const char* password = "";
// const char* ntpServer = "pool.ntp.org";
// const long gmtOffset_sec = 0;
// const int daylightOffset_sec = 3600;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); //creating a object for the OLED display
//we have to specify screen width, screen height, wire libry and reset pin
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //initialize the serial communication
//to initialize the oled display we are using the begin function
//the input we have to provide in the documentation of the libry
//then we have to give the address of the display
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); //dont proceed loop forever
}
//if clause is there to show us whether the oled is display is initialized properly
//exclamation mark is logical not operator
//when the display is not properly initialized the condition will become false and print the line
//because of the infinite for loop without any input...so the code will not execute beyond when the oled isplay is not working.
//show initial display buffer contents on the screen
//the library initializes this with an adafruit splash screen
display.display();
delay(2000); //pause for 3 seconds
//clear the buffer
//buffer is like the logo of the company
display.clearDisplay(); //here we are starting the display
display.setTextSize(1); //adding a text size for the display
display.setTextColor(SSD1306_WHITE); //adding a text color
display.setCursor(0,0); //getting the cursor to the origin
display.println(F("welcome to medibox"));
display.display();
// // connect to the wifi
// Serial.print("Connecting to ");
// Serial.println(ssid);
// WiFi.begin(ssid, password);
// while (WiFi.status() != WL_CONNECTED) {
// delay(500);
// Serial.print(".");
// }
// Serial.println("");
// Serial.println("WiFi connected.");
// // Init and get the time
// configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
// printLocalTime();
// // disconnect WiFi as it is no longer needed.
// WiFi.disconnect(true);
// WiFi.mode(WIFI_OFF);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
// void printLocalTime() {
// struct tm timeinfo;
// if (!getLocalTime(&timeinfo)) {
// Serial.println("Failed to obtain time");
// return;
// }
// Serial.println(&timeinfo, "%A, %B %d %H:%M:%S");
// }