Simple Time Counter (stopwatch)
Posted: Thu Nov 02, 2023 4:10 pm
by DoDobro!
Hello,
Can't find how at ArduinoIDE2 with ESP32S3 create and use simple SW or HW Time Counter (aka "stopwatch") without needing any additional libraries etc. No tasks, no interrupt, just count time in seconds from 00:00:00:00 (hr:mn:sc:milsc) at 24hr format maybe with days in front like 01:23:59:59:1000? Seems very simple, but can't find how to make it without any additional libraries and complex [struct] etc which I don't need!
Re: Simple Time Counter (stopwatch)
Posted: Fri Nov 03, 2023 4:31 am
by mikemoy
Re: Simple Time Counter (stopwatch)
Posted: Fri Nov 03, 2023 5:12 am
by username
Asked chat GPT and here is it's response.
Code: Select all
#include "esp_system.h"
#include "esp_timer.h"
#include "esp_log.h"
void app_main() {
// Initialize the system
esp_err_t ret = esp_system_initialize();
if (ret != ESP_OK) {
ESP_LOGE("main", "Initialization failed, error = %d", ret);
return;
}
// Get the current uptime in milliseconds
uint64_t uptime_ms = esp_timer_get_time() / 1000;
// Display the uptime in seconds
ESP_LOGI("main", "Uptime: %llu seconds", uptime_ms / 1000);
// You can also convert uptime to hours, minutes, and seconds if needed
uint64_t seconds = uptime_ms / 1000;
uint64_t minutes = seconds / 60;
uint64_t hours = minutes / 60;
seconds %= 60;
minutes %= 60;
ESP_LOGI("main", "Uptime: %llu hours, %llu minutes, %llu seconds", hours, minutes, seconds);
}
Re: Simple Time Counter (stopwatch)
Posted: Fri Nov 03, 2023 5:21 pm
by DoDobro!
For Arduino!
username wrote: ↑Fri Nov 03, 2023 5:12 am
Asked chat GPT and here is it's response.
Code: Select all
#include "esp_system.h"
#include "esp_timer.h"
#include "esp_log.h"
More simple, withOUT 3 #include!
Re: Simple Time Counter (stopwatch)
Posted: Fri Nov 03, 2023 8:12 pm
by username
More simple, withOUT 3 #include!
Just curious, what the issue with #include?
You already #include arduino.h, and that one line pulls in a ton of stuff.