Simple Time Counter (stopwatch)

DoDobro!
Posts: 14
Joined: Mon Oct 02, 2023 4:39 pm

Simple Time Counter (stopwatch)

Postby DoDobro! » Thu Nov 02, 2023 4:10 pm

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!

mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

Re: Simple Time Counter (stopwatch)

Postby mikemoy » Fri Nov 03, 2023 4:31 am


username
Posts: 532
Joined: Thu May 03, 2018 1:18 pm

Re: Simple Time Counter (stopwatch)

Postby username » 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"

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);
}

DoDobro!
Posts: 14
Joined: Mon Oct 02, 2023 4:39 pm

Re: Simple Time Counter (stopwatch)

Postby DoDobro! » Fri Nov 03, 2023 5:21 pm

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!

username
Posts: 532
Joined: Thu May 03, 2018 1:18 pm

Re: Simple Time Counter (stopwatch)

Postby username » Fri Nov 03, 2023 8:12 pm

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.

Who is online

Users browsing this forum: Bing [Bot] and 103 guests