Quad X Type Multicopter

Dependencies:   IAP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PulseWidthCounter.cpp Source File

PulseWidthCounter.cpp

00001 #include "mbed.h"
00002 #include "InterruptIn.h"
00003 #include "PulseWidthCounter.h"
00004 
00005 PulseWidthCounter::PulseWidthCounter(PinName inpin,bool positive) : pulsein(inpin)     //constructa  
00006 {
00007     if ( positive ) 
00008     {   pulsein.rise(callback(this,&PulseWidthCounter::start));
00009         pulsein.fall(callback(this,&PulseWidthCounter::stop));
00010     }
00011     else
00012     {   pulsein.fall(callback(this,&PulseWidthCounter::start));
00013         pulsein.rise(callback(this,&PulseWidthCounter::stop));
00014     }
00015 }
00016 
00017 void PulseWidthCounter::start()
00018 {
00019     _time.reset();
00020     _time.start();
00021 }
00022 
00023 void PulseWidthCounter::stop()
00024 {
00025     _time.stop();
00026     count = _time.read_us();
00027 }
00028