Measure the width (time-wise) of an incoming pulse.
Dependencies: dispBoB mbed PCA9635
counter.cpp
- Committer:
- d_worrall
- Date:
- 2011-07-11
- Revision:
- 1:f04131cae8b8
- Parent:
- 0:dd684fb95312
- Child:
- 2:bb7e46464d17
File content as of revision 1:f04131cae8b8:
#include "mbed.h" #include "dispBoB.h" dispBoB db(p28, p27, p26); //instantiate a dispBoB object InterruptIn trigger(p12); //set up the trigger as an external interrupt Timer t; void up(){ //call this on rising edge t.start(); //start timer } void down(){ //call this upon falling edge t.stop(); //stop timer db.locate(0); db.printf("%06d", t.read_ms()); //print counter info to dispBoB t.reset(); //reset timer } int main() { trigger.mode(PullUp); //activate internal pull up (hardware specific) db.init(); //again ALWAYS initialise dispBoB db.cls(); //clear screen trigger.rise(&up); //attach up() to interrupt on rising edge of trigger trigger.fall(&down); //attach down() to interrupt on falling edge of trigger db.printf("%06d", t.read_ms()); //display an inital count "000000" }