Author Topic: Stopwatch - Lua Timer Accuracy  (Read 4339 times)

0 Members and 1 Guest are viewing this topic.

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Stopwatch - Lua Timer Accuracy
« on: December 11, 2011, 01:43:46 pm »
Recently, I have been trying to build a stopwatch for Nspire with Lua. However, when run, it obviously slows down. My program used a timer with 0.1 seconds, but I changed it so it had a timer with 0.09 seconds. That was still a bit slow, but 0.08 seconds is a bit too fast. The timer can't do anything with less than 0.01 as experimentation and the Inspired Lua wiki have shown.

Is there any way the timer could be fixed so it is more accurate? Or is there another way to do this?

P.S. My program uses tenths of a second, not hundredths or thousandths.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Stopwatch - Lua Timer Accuracy
« Reply #1 on: December 11, 2011, 01:57:32 pm »
Not sure...

TI made a Lua script for a stopwatch, you can download it here : http://tiplanet.org/forum/archives_voir.php?id=3613&play= (click on the "Télécharger" button)
« Last Edit: December 11, 2011, 01:57:38 pm by adriweb »
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Stopwatch - Lua Timer Accuracy
« Reply #2 on: December 11, 2011, 02:03:47 pm »
you could use the timer.getMilliSecCounter instead, because the timer isn't correct at all..
if you store the start millisec and increment by the current millisec, you get the millisec that are passed since the start of the program.
when you divide by 1000, you get the nr of seconds (and take the math.floor() of it)

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Re: Stopwatch - Lua Timer Accuracy
« Reply #3 on: December 11, 2011, 02:16:29 pm »
Thanks to both of you! I'll try the getMilliSecCounter.

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Stopwatch - Lua Timer Accuracy
« Reply #4 on: December 11, 2011, 03:53:15 pm »
you could use the timer.getMilliSecCounter instead, because the timer isn't correct at all..
if you store the start millisec and increment by the current millisec, you get the millisec that are passed since the start of the program.
when you divide by 1000, you get the nr of seconds (and take the math.floor() of it)

Of course... I actually assumed he was using it, I must have misread then :P

And yes, it will be much more precise :)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation