Measure the width (time-wise) of an incoming pulse.

Dependencies:   dispBoB mbed PCA9635

counter.cpp

Committer:
d_worrall
Date:
2011-07-11
Revision:
0:dd684fb95312
Child:
1:f04131cae8b8

File content as of revision 0:dd684fb95312:

#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(){                       //function to call upon interrupt
    t.start();
}

void down(){
    t.stop();
    db.locate(0);
    db.printf("%06d", t.read_ms());     //print counter info to dispBoB 
    t.reset();
    t.start();
}

int main() {
    trigger.mode(PullUp);           //activate internal pull up (hardware specific)
    db.init();
    db.cls();                       //clear screen
    trigger.rise(&up);           //attach count() to interrupt on rising edge of trigger
    trigger.fall(&down);
    db.printf("%06d", t.read_ms()); //display an inital count "000000"
}