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.
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?
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?
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.
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.
@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?