Getting time

Adding high-resolution timer to imp API would be nice.

I second this request.

I know you can use imp.sleep(float) to insert microsecond precision delays.
But is there anything equivalent to the Arduino micros() API?

As one example, I want to read a single-bus protocol from an AM2303 sensor. I need to time the duration of pulses received to distinguish 0s from 1s.

I made a similar request here: http://forums.electricimp.com/discussion/274/uart-api-issues#Item_4

For now you can use the clock() function (see the squirrel reference manual). It’s only centisecond resolution but its available already.

Thanks.

Unfortunately for this sensor, a ‘0’ is a 26usec pulse and a ‘1’ is a 70usec pulse.

For now I will just use imp.sleep(20 usec) in combination with an event that triggers on any level change of the GPIO and share a global state between the two event handlers.

Unless they release a micros() API before I sit down with this again.