Used to read incoming PWM signals from RC channels
Diff: PulseIn.cpp
- Revision:
- 0:1a57c7f88422
- Child:
- 1:eaf70ff4df07
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PulseIn.cpp Wed Dec 19 08:06:23 2012 +0000 @@ -0,0 +1,28 @@ +#include "PulseIn.h" +#include "mbed.h" + +PulseIn::PulseIn(PinName p) : _k(p) +{ + _k.rise(this, &PulseIn::rise); + _k.fall(this, &PulseIn::fall); + _duration=0; + +} + +int PulseIn::read() +{ + return _duration; +} + +void PulseIn::rise() +{ + t.start(); +} + +void PulseIn::fall() +{ + t.stop(); + _duration = t.read_us(); + t.reset(); +} + \ No newline at end of file