How can I set Time Limit for certain tasks to be completed?

Hi, in my app, I wish to run certain if conditions. But all those if conditions must be completed within 20 seconds. If all the tasks in if conditions are succeeded within 20 seconds then 'LabelText = Task Completed' else 'LabelText = Task Failed'. How can I set time limit for certain blocks to function within that time limit?

eg. If the pedometer walksteps are more than 20 in 20 seconds then Task completed else Task Failed.

Use a clock, set the interval to 20, and when the event is triggered check the condition (in your example is walk steps > 20) to set the labe to Completed or to Failed.

@Ramon , I shall give one more example. This is what precisely I need.

We know that the accelerometer value keeps on varying always (raise and fall in values). So, my if condition is as follows

  1. If the Accelerometer value reached to +3, then check again for the same value ie, +3.

  2. Repeat the above step, 3 more times with interval gap of 250 ms.

  3. If +3 value is detected totally four times within 20 seconds, then 'Task Acheived' else 'Task Not Acheived'.

Okay, I can guess. Il try.

You need there two clocks then...The first one with 20s. interval and the second one with 250ms interval.

And two counters...the firs one for the 3 repetition of the clock(250ms) and the second one to count how many times +3 is reached in 20s.

1 Like

Can you tell me the steps to create counter? I watched few youtube videos but those counters are only about adding 1 while pressing button each time. How can I create counter for this accelerometer application?

Okay, il try.

If the first counter is to know when the timer (250ms) has been triggered 3 times, then each time the timer event triggers set counter++. If counter = 3, then stop the timer.

If the second counter is to control how many times +3 is reached then, each time you has checked that +3 is reached, counter2++. If counter2=4 (before timer of 20s expired) "Task achieved".

Okay, let me create blocks for that. And, how can I loop the clock to function for every 250 ms interval? Is it automatic or do I have to do something for that?

For example,


Do, I have to do any thing more so it will function repetitively in loop or is it enough for that?

"Automatic". So, every 250ms, the event will be triggered. Until you disable the timer.

1 Like

you need two different timers, one triggered each 250ms and other for 20s.

you don't need to enable again the timer inside the Timer block.

If you want to repeat the cycle of 250ms only 3 times once the first XAccel>3, then you need a variable (counter), to increment in each cycle and checking if the total number of cycles (3, if i understood you) has been reached to stop the timer_250ms.

In each cycle, you have to check if XAccel is >3, to accumulate it in another variable.

The Timer of 20s, when triggered I suppose you only have to stop it and check if this second variable is, at least, equal to 4 to get the target.

This is my knowledge limit. Can you create blocks in a proper way as it should be?

If I have understood what you wat it would be something like this.

First time xAccel>=3, it starts a timer with an interval = 20s and the counter of number of times +3 reached is set to 1 (counterCondition).
It also starts a time with interval=250ms, which will stop after 3 cycles. This timer will complete its 3 cycles and only will be triggered again if the
condition xAccel>=3 is matched again.

During each 250ms cycles (3) it is checked if xAccel>=3 to increment by 1 the counterCondition.

Once the timer of 20s expires, it is checked if counterCondition>=4, that is, if the condition XAccel>=3 occurred 4 times.

During the time that timer_20s is running it is not triggered again. During the time the timer_250ms is running, it does not fire again.

1 Like

@Ramon, But, for some reason this app/blocks are not working in my phone as explained above.

I tilted phone more than 3 times in such a way that x value will reach 3. i waited for 20 seconds but I didn't get message as Task achieved. Can you share the app file (.aab) here?

I didn't compile it. It was an example to iustrate the idea. I'm with the phone now so I can't check it deeper.

Decelerating your car feels just like accelerating your car, just in the reverse direction on the phone.

Unless you clamp your phone to the car, how would you tell the difference?

1 Like

Okay, Can you share later?

Expecting beneficial help with solution.

This block is working.

Now only, I can understand that the count is increasing very fastly. So, we have to modify the blocks accordingly.

Thankyou very much @Ramon for sharing knowledge. Let me try creating blocks.

Eventhough the above block worked well, when i included clock and tried to get x value only after every 60 second, things are not working.