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

Dependencies:   dispBoB mbed PCA9635

Committer:
d_worrall
Date:
Mon Jul 11 13:41:08 2011 +0000
Revision:
0:dd684fb95312
Child:
1:f04131cae8b8
version1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
d_worrall 0:dd684fb95312 1 #include "mbed.h"
d_worrall 0:dd684fb95312 2 #include "dispBoB.h"
d_worrall 0:dd684fb95312 3
d_worrall 0:dd684fb95312 4 dispBoB db(p28, p27, p26); //instantiate a dispBoB object
d_worrall 0:dd684fb95312 5 InterruptIn trigger(p12); //set up the trigger as an external interrupt
d_worrall 0:dd684fb95312 6 Timer t;
d_worrall 0:dd684fb95312 7
d_worrall 0:dd684fb95312 8 void up(){ //function to call upon interrupt
d_worrall 0:dd684fb95312 9 t.start();
d_worrall 0:dd684fb95312 10 }
d_worrall 0:dd684fb95312 11
d_worrall 0:dd684fb95312 12 void down(){
d_worrall 0:dd684fb95312 13 t.stop();
d_worrall 0:dd684fb95312 14 db.locate(0);
d_worrall 0:dd684fb95312 15 db.printf("%06d", t.read_ms()); //print counter info to dispBoB
d_worrall 0:dd684fb95312 16 t.reset();
d_worrall 0:dd684fb95312 17 t.start();
d_worrall 0:dd684fb95312 18 }
d_worrall 0:dd684fb95312 19
d_worrall 0:dd684fb95312 20 int main() {
d_worrall 0:dd684fb95312 21 trigger.mode(PullUp); //activate internal pull up (hardware specific)
d_worrall 0:dd684fb95312 22 db.init();
d_worrall 0:dd684fb95312 23 db.cls(); //clear screen
d_worrall 0:dd684fb95312 24 trigger.rise(&up); //attach count() to interrupt on rising edge of trigger
d_worrall 0:dd684fb95312 25 trigger.fall(&down);
d_worrall 0:dd684fb95312 26 db.printf("%06d", t.read_ms()); //display an inital count "000000"
d_worrall 0:dd684fb95312 27 }