#include "Arduino.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <HTTPClient.h>
#include <WiFi.h>
#include <NTPClient.h>
const char* ntpServer = "pool.ntp.org";
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, ntpServer);
//Digital I/O used //Makerfabs Audio V2.0
#define I2S_DOUT 27
#define I2S_BCLK 26
#define I2S_LRC 25
//SSD1306
#define MAKEPYTHON_ESP32_SDA 4
#define MAKEPYTHON_ESP32_SCL 5
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const char *ssid = "Wokwi-GUEST";
const char *password = "";
int runtime = 0;
int length = 0;
bool isPaused = false;
unsigned long previousMillis = 0;
unsigned long interval = 30000;
int ledState = LOW;
void lcd_text(String text, int textSize, int text_position, String text2="")
{
display.setTextSize(textSize); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, text_position); // Start at top-left corner
display.clearDisplay();
display.println(text);
if (text2)
display.setTextSize(1); // Normal 1:1 pixel scale
display.println(text2);
display.display();
}
void setup()
{
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
// Initialize the NTP client
timeClient.begin();
timeClient.setTimeOffset(0); // Adjust the time offset if necessar
timeClient.update();
// Get the current date and time
// Get the current date and time components
int day = timeClient.getDay();
int hour = timeClient.getHours();
int minute = timeClient.getMinutes();
int second = timeClient.getSeconds();
// Display the date and time
Serial.println(day);
Serial.print("Time: ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setRotation(1);
display.setTextColor(SSD1306_WHITE); // Draw white text
}
String getLocalTime(){
struct tm timeinfo;
while(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
}
char timeHour[3];
char timeMinute[3];
strftime(timeHour,3, "%H", &timeinfo);
strftime(timeMinute,3, "%M", &timeinfo);
return String(timeHour) + ":" + String(timeMinute) + ":";
Serial.println(timeHour);
}
void loop()
{
unsigned long currentMillis = millis();
Serial.println(currentMillis);
if ( currentMillis - previousMillis >= 1500){
previousMillis = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
if (ledState == HIGH)
{
lcd_text("A", 1, 0);
}
else if (ledState == LOW)
{
lcd_text("B", 1, 0);
}
}
}