Stopwatch Timer for Action Button

In an attempt to get students to gather the data, I’m attempting to have them use the Action Button to start (and stop) a timer, like a stopwatch.


•1. So far I can get the time to start when the pressCount=1, but when the pressCount=2 (or used the ResetButton feature) it just clears the data. I’d like it to capture the last time, when the button (or reset button) is pressed and put that in the table.

•2. Also, I can’t seem to get the simplefunction to sinc with the time to the button press. (I need it display in to the tenth place)

Here’s what I’ve got so far:
TABLE:
time=btn1.timeSincePress()
time = simpleFunction("\operatorname{floor}(10x)/10").evaluateAt.???
timeStopped=???
cellContent(1,1): when btn1.pressCount=1 “${time} seconds”
when btn1.pressCount=2 time (timeStopped)
otherwise “”
BUTTON:
label: when btn1.pressCount=0 “Start!”
when btn1.pressCount=1 “Stop Timer” otherwise “”
hidden: when btn1.pressCount =2 true otherwise false

Any suggestions for these 2 things? Thanks!

1 Like

I had better luck (and time) with the capturing today. This worked for me.

Table

time1 = simpleFunction("\\operatorname{round}(x,1)").evaluateAt(btn1.timeSincePress)
time2 = simpleFunction("\\operatorname{round}(x,1)").evaluateAt(btn1.lastValue("T"))

cellContent(1,1): when btn1.pressCount=1 "${time1} seconds"
when btn1.pressCount=2 "${time2} seconds"
otherwise ""

Button

label: when btn1.pressCount=0 "Start!" 
when btn1.pressCount=1 "Stop Timer"
otherwise ""

hidden: when btn1.pressCount =2 true otherwise false

capture("T"): btn1.timeSincePress(120)

This is a similar strategy that I used for the woodchucking activity, so I don’t know why that one wasn’t working. Just a tip for your second issue, you needed two backslashes in your floor function, so you may have been close to getting it at some point. I just used the round function since it’s less work!

Yeah! That worked perfectly! Then that helped me search out some other code to make the button loop and change color.
I added a way to reset it and change the color for the “reset” too!
*Check it out now.
Table:

button=btn1
value = numericValue("\\mod(${button.pressCount}, 3)")
start=value=1
stop= value=2
reset=value=3

time1 = simpleFunction("\\operatorname{round(x,1)").evaluateAt(button.timeSincePress)
time2 = simpleFunction("\\operatorname{round(x,1)").evaluateAt(button.lastValue("T"))

cellContent(1,1): 
when start "${time1} seconds"
when stop "${time2} seconds"
otherwise ""

Action Button CL:

button=btn1
capture("T"): button.timeSincePress(120)

value = numericValue("\\mod(${button.pressCount}, 3)")
start=value=0
stop= value=1
reset=value=2

style: 
when stop buttonStyles.red
when reset buttonStyles.link
otherwise buttonStyles.default

label: 
when start "Start!" 
when stop "Stop Timer"
when reset "Press to Reset"
otherwise ""

This is now exactly what I needed! Thanks @cwinske for the jumpstart!