positive or negative pulse width counter
PulseCounter.cpp
- Committer:
- komaida424
- Date:
- 2013-07-10
- Revision:
- 0:89bd4ad6027d
File content as of revision 0:89bd4ad6027d:
#include "mbed.h" #include "InterruptIn.h" #include "PulseCounter.h" PulseCounter::PulseCounter(PinName _interrupt,bool positive=true) : interrupt(_interrupt) //constructa { if ( positive ) { interrupt.rise(this,&PulseCounter::start); interrupt.fall(this,&PulseCounter::stop); } else { interrupt.fall(this,&PulseCounter::start); interrupt.rise(this,&PulseCounter::stop); } } void PulseCounter::start() { _time.reset(); _time.start(); } void PulseCounter::stop() { _time.stop(); count = _time.read_us(); }