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