Sub Globals
secSecond=0
secFirst=0
End Sub
Sub App_Start
Form1.Show
End Sub
Sub button1_click
secSecond=Now
If secFirst=0 Then
secFirst = Now
label1.text="start"
label2.text="start"
End If
r=secSecond-secFirst
If r>0 Then
label1.text=Round(r/ctickspersecond,2)
bpmAvg = Round(60/(r/ctickspersecond),0)
label2.text=bpmAvg
End If
secFirst=secSecond
End Sub
It may be because of the use of a button control...
remove the button and use the code in the form _click event...
Buttons seem to have some kind of latency time...perhaps to avoid double clikcs when only one was meant...
Hi Cor/Cableguy,
I have tried the code on my device and same result what cor is getting...
I've found out that the 'Now' ticks returns on device like 633375480580000000 means no milliseconds unlike on desktop. Why??
I guess that the only solution is to use your own timer.
Then if it is improtant that it stays in sync with the system time you may need to compare your time with the system time and adjust as necessary.
Sub Globals
n=0
End Sub
Sub App_Start
Form1.show
timer1.Enabled=true
timer1.Interval=1
End Sub
Sub Timer1_Tick
n=n+1
label1.Text=n/200
End Sub
Sub Button1_Click
label2.Text=Round(n/200,2)
label3.Text=Round(60/(n/200),0)
n=0
End Sub
EDIT: CODE is for device, use n/100 on desktop, also finetune as Randomcoder's advice.
Hi Alfcen,
Thanks for pointing dzt's dzWH.dll. Problem solved!
Hi Cor, we could use the first code and change 'Now' with 'GetTickCount' and divide by 1000 for seconds lapses per beat.
B4X:
Sub Globals
secSecond=0
secFirst=0
End Sub
Sub App_Start
Form1.Show
dzH.New1 'dzHW.dll object
End Sub
Sub button1_click
secSecond=dzh.GetTickCount
If secFirst=0 Then
secFirst = dzh.GetTickCount
label1.text="start"
label2.text="start"
End If
rt=secSecond-secFirst
If rt>0 Then
label1.text=Round(rt/1000,2)
bpmAvg = Round(60/(rt/1000),0)
label2.text=bpmAvg
End If
secFirst=secSecond
End Sub