Timer Example
Moderator: cpp4robots_admin
Timer Example
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.
-
- Administrátor fóra
- Posts: 21
- Joined: 04 Nov 2020 14:34
- Contact:
Re: Timer Example
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
Is it needed/advised to put a sleep in the while loop? To prevent 100% CPU load?
-
- Administrátor fóra
- Posts: 21
- Joined: 04 Nov 2020 14:34
- Contact:
Re: Timer Example
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.
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
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.
It depends a bit on the multi-threading system of the EV3 or cpp4robots.
Last bumped by Anonymous on 01 May 2021 05:12.
Who is online
Users browsing this forum: No registered users and 4 guests