Measure the time interval between two consecutive rising edges

Dependencies:   dispBoB mbed PCA9635

Committer:
d_worrall
Date:
Mon Jul 11 13:42:00 2011 +0000
Revision:
0:37bc70ca825c
Child:
1:b56440e55747
version1

Who changed what in which revision?

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