2017년 7월 15일 토요일

Clock duration


I'm trying to calculate an event's duration (i.e Calculate how long the phone is tilted over a given period) with the clock.duration block but whatever i try i have this message "cannot accept arguments true or false". I don't understand and I don't find any tuto with this block.

If anybody has an idea, this will be a helpfull !

--
How to get the duration between 2 instants in hours, minutes and seconds

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

--
It's very basic...I'm still a beginner.

Thanks for your help


-- 
Here's a short quick answer - 

You need just two global variables:

Last Band Number, with possible values 1,2, or 3
depending on the last angle range
(band 1 = 0 to 20,
 band 2 = 20 to 40,
 band 3 = over 40)

Band_entry_Instant_ms = the Instant (in milliseconds from 1970) we
last entered the band mentioned in Last Band Number.

You will also need a procedure to select and update a label based on band number.

In your repeating event, either a Clock Timer or the sensor's event,
do this:

set all 3 labels to 0  (optional)
calculate a temporary local value for the current band from the sensor
If current band = global Last Band Number then
   set Label.Text number(last band) to Clock1.current_time_ms - Band_entry_Instant_ms
else 
   set Label.Text number(last band) to 0
   set Band_entry_Instant_ms to Clock1.current_time_ms
   set Last Band Number to current band

-- 
I don't have an orientation sensor device at hand to test with,
but I think the attached blocks and source should do
what you want.

I used Magnitude instead of angle to pick the band.
Feel free to change it per taste.



-- 
By the way, if you leave the device on a stable table top, and
the orientation doesn't change, the display may not update.

If that's a problem, switch to a clock.timer event for your repeating action.

-- 

I've just tried your answer but It doesn't seem to work (with magnitude or angle) : labels still indicate "0" whatever the phone position. Perhaps I missed something ?

-- 
Post a blocks image and a .aia export for us to try?

-- 
 I've forgoten to delete a block on my file that's why it didn't work. It works with your aia file (except for the intermediate angle "band = 2" indicating "0" whatever phone position).

-- 

댓글 없음:

댓글 쓰기