Accelerometer Sensor: How do you detect continuous shaking for 5 seconds?

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

Thank you so much!

I will try and update you how it went

by Clock.SystemTime

Do you mean Clock1.TimeInterval?

I don't see the system time in the clock drawer hehehe


My apologies, thank you!

Here are the updated blocks:


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.



Clock timerInterval does not need to be 5000...

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.

Move the timer enabled block to where the arrow points !

Got it!

Thank you so much it works

Here's my working sample.

Sorry it's so late, I needed a nap.

Sample run
shake_and_bake.aia (3.1 KB)

Woahhh, thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.