Author Topic: Stopwatch program help  (Read 2784 times)

0 Members and 1 Guest are viewing this topic.

Offline dinhotheone

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 410
  • Rating: +2/-1
    • View Profile
Stopwatch program help
« on: January 05, 2007, 10:55:00 am »
I have a problem, my science teacher wanted me to create a stopwatch prgram on the ti 84. This has proven far more difficult than i initially expected. i have tried aaround 6 methods and only one has been any good. the only problem is that it doesnt work for timing's less than one secong. ill explain my code.

BTW if you only know how to prgm on 83-83+SE the functions in the program you dont know are....
Starttimer - returns the value of the clock the calculator is on. This number is usually really big,
Checktimer(variable) - when you store the starttimer value to a variable and put it into the checktimer, this returns the amount of time that has
elapsed.
Thats it

Here is some pseudo code-ish stuff of my code becuase i know of no other way to display code.

Starttimer STO B
Repeat untill the time changes from B
End
"this is to ensure that i start calibration at the start of the second and not in the middle"
Repeat untill 3 seconds have passed
A+1 STO A
end
A/2 STO A
"that was calibration ^"
pause
starttimer STO B
repeat untill the time changes from B
C+1 STO C
end
"this records the time it takes before the first second is hit, to make up for starting timer with fraction a second gone by in timer"
repeat ans
getkey
end
checktimer(B ) - 1 STO S
repeat untill time changes from S
D+1 STO D
end
A-D STO D
"this is to check how many fractions of a second passed after the last full second"

From here i add D and C and divide that by A and then add that to S and get the total number of seconds. The Reason the program doesnt work for fractions of a second is because the timer on the calc is always going so when i press endter after the pause, it checks to see how much time goes by before the first second change. if the person tries to stop the time here it wont react, if i input some getkey stopping in here then the speed in the calibration and the timing loops will differ, if i add getkey to both then i have to add it to the third iteration counter and make each iteration slower making the prog more imprecise.

So, can anyone help? I hope i didnt confuse you ... I hope i didnt miss something obvious. Also if anyone knows of a way to Start the timer so that i will not have to deal with fractions of a second except at the termination of the program... that would do.

misirlou

  • Guest
Stopwatch program help
« Reply #1 on: January 05, 2007, 05:05:00 pm »
Instead of using the clock commands on the calc, try using a for loop instead.
->X
->K
repeat K=22
For(T,1,*number you need to get one hundreth of a second*
End
X+.01->X
Output(1,1,X
getkey->K
End

With this it stops when you press 2nd. The only problem with this is itll be really tough to time it right. I would plug in numbers and try to get it accurate to ten seconds, then to a minute, and so on depending on how accurate you want it to be. I actually think this is probably too long to take a hundreth of a second even without the for loop. Idk maybe if you did tenths of a second it would work.

Offline dinhotheone

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 410
  • Rating: +2/-1
    • View Profile
Stopwatch program help
« Reply #2 on: January 15, 2007, 10:23:00 am »
ya, i figured it out, i changed alot of stuff and set the calibration for like 4 seconds, instead of 1 or 2. The problem misirlou, is that i need to calibrate the program each time it is executed and i don't know how to do it for that code.

elfprince13

  • Guest
Stopwatch program help
« Reply #3 on: January 15, 2007, 11:01:00 am »
no, do not use the calibrated for loop, thats horrid

c1-->
CODE
ec1
Disp "Press 2nd to start"
Repeat getKey=21
End
checkTimer->T
Disp "press 2nd to stop"
Repeat getKey=21
End
Disp checkTimer(T
c2
ec2

Offline dinhotheone

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 410
  • Rating: +2/-1
    • View Profile
Stopwatch program help
« Reply #4 on: January 16, 2007, 01:30:00 pm »
i need it to keep track of up more than just seconds though, and if im not sorely mistaken, the timer only keeps track of whole seconds, not hundredths or even tenths. also this is for use in a physics classroom so it will be timing multiple times per program execution, it only calibrates at the start the program, not at each timing.

elfprince13

  • Guest
Stopwatch program help
« Reply #5 on: January 16, 2007, 03:58:00 pm »
well, if you want less than a second, learn asm.

Offline necro

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1295
  • Rating: +17/-2
  • +3 vaporal mustache
    • View Profile
Stopwatch program help
« Reply #6 on: January 16, 2007, 05:46:00 pm »
QuoteBegin-misirlou+6 Jan, 2007, 4:05-->
QUOTE (misirlou @ 6 Jan, 2007, 4:05)
Instead of using the clock commands on the calc, try using a for loop instead.
->X
->K
repeat K=22
For(T,1,*number you need to get one hundreth of a second*
End
X+.01->X
Output(1,1,X
getkey->K
End

With this it stops when you press 2nd. The only problem with this is itll be really tough to time it right. I would plug in numbers and try to get it accurate to ten seconds, then to a minute, and so on depending on how accurate you want it to be. I actually think this is probably too long to take a hundreth of a second even without the for loop. Idk maybe if you did tenths of a second it would work.  

 problem is, that would vary with the battery power Id think

i don't have an 84 so I am unsure how the clock drystal functions work but look at your manual to see if there are any ways to make a smaller interval (assuming it comes with one)
I'm like a woot burger with awesome fries


VB.Net, C#, C++, Java, Game Maker

elfprince13

  • Guest
Stopwatch program help
« Reply #7 on: January 16, 2007, 07:20:00 pm »
QuoteBegin-necro+16 Jan, 2007, 23:46-->
QUOTE (necro @ 16 Jan, 2007, 23:46)
QuoteBegin-misirlou+6 Jan, 2007, 4:05-->
QUOTE (misirlou @ 6 Jan, 2007, 4:05)
Instead of using the clock commands on the calc, try using a for loop instead.
->X
->K
repeat K=22
For(T,1,*number you need to get one hundreth of a second*
End
X+.01->X
Output(1,1,X
getkey->K
End

With this it stops when you press 2nd. The only problem with this is itll be really tough to time it right. I would plug in numbers and try to get it accurate to ten seconds, then to a minute, and so on depending on how accurate you want it to be. I actually think this is probably too long to take a hundreth of a second even without the for loop. Idk maybe if you did tenths of a second it would work.

problem is, that would vary with the battery power Id think

i don't have an 84 so I am unsure how the clock drystal functions work but look at your manual to see if there are any ways to make a smaller interval (assuming it comes with one)  

 the 84 manual is s***ty, and there is no way to use Basic to get more accurate than a second with the built in clock functions. however I believe the clock does tick more frequently than that so I would write one in assembly, and use that.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Stopwatch program help
« Reply #8 on: January 17, 2007, 03:08:00 am »
it is very hard in basic to have accurate clock,even with for loops, especially if there is lot of functions in the main loop
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)