/*
* This ESP32 code is created by esp32io.com
*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-oled
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
float t,h;
t=25;
h=80;
pinMode(15, OUTPUT);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(1000); // wait two seconds for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(2); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 10); // set position to display
oled.println("Hi~~~"); // set text
oled.println("Count time");
oled.println("3..2..1!");
oled.display(); // display on OLED
delay(5000);
oled.clearDisplay(); // clear display
oled.setTextSize(2);
oled.setCursor(30, 30);
oled.println("Go!!!!");
oled.display(); // display on OLED
delay(5000);
oled.clearDisplay();
oled.display();
}
int Hr,Min,Sec;
void loop()
{
int time_now = millis()/1000;
Sec = time_now%60;
if(Sec==0)
{
Min++;
if(Min>59)
{
Min=0;
Hr++;
}
}
oled.clearDisplay(); // clear display
oled.setTextSize(1.5); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 10); // set position to display
oled.println("Time Counter"); // set text
oled.print("Sec = ");
oled.println(Sec);
oled.print("Min = ");
oled.println(Min);
oled.print("Hr = ");
oled.println(Hr);
oled.display();
delay(1000);
if (Min>=1,Min<4){
digitalWrite(15, HIGH);
}else{
digitalWrite(15, LOW);
}
}