//Naming the only input
int button = 15;
int n = 0;
//global variables
unsigned long timeNow_Sum = 0;
unsigned long initialTime = 0;
long seconds = 0;
long hours = 0;
long minutes = 0;
void setup() {
//Trying to display time only once
// put your setup code here, to run once:
pinMode(button, INPUT);
Serial.begin(115200);
Serial.println("Hello, ESP32!");
}
void loop() {
timeNow_Sum = millis()/1000;
seconds = timeNow_Sum - initialTime;
if (seconds == 60){
minutes = minutes + 1;
seconds = 0;
initialTime = initialTime + 60;
}
if (minutes == 60){
hours = hours + 1;
minutes = 0;
}
//Ouputing the Ouput
//Checking the state of the button
int button_state = digitalRead(button);
if (button_state == LOW){
Serial.println(String(hours) + ":" + String(minutes) + ":" + String(seconds));
delay(200); //Using delay hinders the program.
}
//Time obtained by the code is therefore not accurate.
}