Timer Example

Moderator: cpp4robots_admin

Robot_Programmer

Timer Example

Post by Robot_Programmer »

Can someone provide me with an example of using the Timer on the EV3? I would like to start a timer, and then display the elapsed time on the LCD display.
cpp4robots_admin
Administrátor fóra
Posts: 21
Joined: 04 Nov 2020 14:34
Contact:

Re: Timer Example

Post by cpp4robots_admin »

Code: Select all

#include <EV3_Timer.h>
#include <EV3_BrickUI.h>
#include <EV3_LCDDisplay.h>


int EV3_main()
{
    using namespace ev3_c_api;

    T_TimerId idTimer = Timer_Start();

    while ( 1 )
    {
        if ( isBrickButtonPressed(E_BTN_ESC) )
            break;

        Draw_Text(3, E_Font_Normal, false, "Elapsed time:");
        Draw_Text(4, E_Font_Normal, false, "%.5lu", Timer_GetTime(idTimer));
    }

    Timer_Destroy(idTimer);

    return 0;
}

surfrider
Posts: 9
Joined: 18 Jan 2021 17:03
Contact:

Re: Timer Example

Post by surfrider »

Is it needed/advised to put a sleep in the while loop? To prevent 100% CPU load?
cpp4robots_admin
Administrátor fóra
Posts: 21
Joined: 04 Nov 2020 14:34
Contact:

Re: Timer Example

Post by cpp4robots_admin »

I'm sorry, but I don't know.
I don't know any tool to find out if our application in EV3 brick uses the processor at 100%.
I don't know if other applications in EV3 brick are affected(slow down) by our process.

In any case, it is a very interesting topic for discussion.
surfrider
Posts: 9
Joined: 18 Jan 2021 17:03
Contact:

Re: Timer Example

Post by surfrider »

Most software I have work on, when you create a thread or have a while loop it is always advised to have at least a very short sleep so the OS can to task switching during the sleep.
It depends a bit on the multi-threading system of the EV3 or cpp4robots.


Last bumped by Anonymous on 01 May 2021 05:12.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest