Hello, I need help regarding this accelerometer sensor. What I need it to do is that when the user is shaking it continuously for 5 seconds straight, the screen will change to a new one.
The sensor is able to detect shaking, however, a little shake immediately transfers the user to the next screen, even if the duration of the shaking did not reach 5 seconds. Do you have any ideas on how to resolve this?
These are my blocks, feel free to tell me what's wrong.
You need a Clock Timer to track how long ago the last shake occurred.
Keep the clock1.SystemTime of the last shake in a global variable (initially zero) for the comparison. The difference is in milliseconds.
P.S. rereading your requirements, you might need two variables.
One for the start of the shake
One for the last shake.
This is my first guess, on my phone:
Init global firstShake=0
Init global lastShake=0
When Shake
If (Clock1.SystemTime - lastShake) > 5000 then
Set firstShake to Clock1.SystemTime
Set lastShake to Clock1.SystemTime
If (lastShake - firstShake) > 5000 then
Set firstShake to 0
Do the thing
However, I am redirected to the new screen after 5 seconds from the first shake, regardless of whether the duration of the shaking is 5 seconds or not.
I need it to detect that the shaking took at least 5 seconds long to be redirected to the new screen because even if I shake it for a little while, it redirects me to the other screen after 5 seconds.
Oh, I just tried to put 0 instead of 5000, in the clock timerInterval, but now what it does is that when it detects a shake, it immediately redirects me to the next screen.