Hi Sam,
Here’s what I was thinking — this code lets you go at 50 frames/sec
while(1) { // your loop
blocks = getBlocks();
if (blocks)
{
// process blocks!
}
else // we may have no blocks, so do some more checking....
{
delay(20); // wait for a frame period
blocks = getBlocks();
if (blocks)
{
// process blocks!
}
else
{
// no blocks detected (guaranteed)
}
}
}
or, you can always do this, which is simpler, but you’ll probably not get 50 frames/sec:
while(1) { // your loop
delay(20); // or you can do something here that takes at least 20 ms
blocks = getBlocks();
if (blocks)
{
// process blocks!
}
else
{
// no blocks detected (guaranteed)
}
}
The main thing to keep in mind is that if you poll faster than 50 times/sec, you will end up with getBlocks being 0 (which is the ambiguous case – does 0 mean no new blocks detected, or does it mean no blocks detected at all in the latest frame), so the first piece of code will work. But if you poll at 50 times/sec or less, you’ll always get the latest blocks (if they exist) and the ambiguous case goes away. If you’re not so worried about 50 frames/sec, I’d used the 2nd piece of code. It’s simpler.