How to implement a similar pulseIn API for FW 0.4.6?


I would like to have a functionality similar to pulseIn (available in 0.4.7). Currently, my application runs on FW 0.4.6.

I would like to measure the time duration of the button press. If the button is pressed for some duration(say 10s), I want to measure that duration in my code.

I am currently thinking of reading the pin status in the corresponding ISR.

//<Sample snippet>
tick1 = System.ticks();
    tick2 = System.ticks();
tick2 -= tick1;

This might not be accurate.

Any suggestion would be of great help.


Any reason not to update to 0.4.9? There have been many improvements since 0.4.6.

@mdma Is release candidate of 0.4.9 available? I like to work on an rc package. Moreover, my application has lots of issues. I want to resolve all these before I switch the FW.

While glancing through the Particle FW reference, I came across System Events. It suggests that the event name button_status provides the duration in ms the button was pressed.

I will try it. Any suggestions, please share.


0.4.9 has been released

button_status is called while the button is being pressed. there’s also button_click which is sent after the button is released.