Quick question that I had a hard time finding in the documentation.
I am trying to do a while loop
that will last for an specific amount of time (like 500ms). How quickly could it do one loop? Every loop will not do a big task, but just read if the light intensity of a sensor is higher than 630nm.
could it work to put every iteration as 1ms?
I am writing in NXC, which is pretty similar to C, I guess...
What you have to do is basically check if the difference between the current system time and the system time at the start is less than your desired value(500ms in this case). As far as how quickly it could do one loop, that depends entirely on your implementation. You could keep track of the time taken for each loop, probably print it for your verification.
As you might be aware currentTick()
returns the current system time in milliseconds. So here's what your code should look like:
unsigned int start, current;
start = currentTick();
current = start;
while(cur < (start+500))
{
//Your task.
current = curTick();
printf("Time: %u",current);
}