YouTube video: http://youtu.be/HF6vH9RonOw
My initial solution for creating a stopwatch was to use a global counter variable to increment the display for each interval of the Clock timer.
That did not work as the Clock Timer does not always fire at exactly the interval specified and there is sometimes a delay.
Instead, I chose to use the Clock getMillis and Now blocks to get a more accurate display to the 1/10th of a second.
When testing if 1/10th second (100ms) have elapsed, I found the the value varies from exaclty 100 to 105 milliseconds.
If it is over 100 milliseconds the StartMs value is adjusted to keep the display on track.
This was tested for a 30 minute period against my PC system clock and I did not see any perceptible difference in the time.
It may fail for much larger time periods, however.
Notes:
When testing this project during development, the emulator will not be able to keep up so use an attached device instead.
You may wish to use the Clock duration block which uses instants rather than doing the calculation with milliseconds as I did here.
YouTube video: http://youtu.be/HF6vH9RonOw
My initial solution for creating a stopwatch was to use a global counter variable to increment the display for each interval of the Clock timer.
That did not work as the Clock Timer does not always fire at exactly the interval specified and there is sometimes a delay.
Instead, I chose to use the Clock getMillis and Now blocks to get a more accurate display to the 1/10th of a second.
When testing if 1/10th second (100ms) have elapsed, I found the the value varies from exaclty 100 to 105 milliseconds.
If it is over 100 milliseconds the StartMs value is adjusted to keep the display on track.
This was tested for a 30 minute period against my PC system clock and I did not see any perceptible difference in the time.
It may fail for much larger time periods, however.
Note: When testing this project during development, the emulator will not be able to keep up so use an attached device instead.