Stopwatch with accuracy to 1/10th second

1,839 views
Skip to first unread message

Scott Ferguson

unread,
Jan 22, 2016, 5:37:42 PM1/22/16
to app-inventor-de...@googlegroups.com

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.


StopWatchOptimized.aia

mla...@marshalltown.k12.ia.us

unread,
Jan 9, 2016, 11:20:44 PM1/9/16
to App Inventor Developers Library
Thank you!  I'll have to look this over in more detail, but the basic concepts makes sense


On Thursday, June 12, 2014 at 3:52:28 AM UTC-5, Scott Ferguson wrote:

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.


Reply all
Reply to author
Forward
0 new messages