Page 1 of 1
Timer Example
Posted: 15 Feb 2021 20:50
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.
Re: Timer Example
Posted: 16 Feb 2021 08:38
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;
}
Re: Timer Example
Posted: 18 Feb 2021 16:02
by surfrider
Is it needed/advised to put a sleep in the while loop? To prevent 100% CPU load?
Re: Timer Example
Posted: 19 Feb 2021 07:39
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.
Re: Timer Example
Posted: 01 May 2021 05:12
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.