Measure the time interval between two consecutive rising edges

Dependencies:   dispBoB mbed PCA9635

Committer:
d_worrall
Date:
Mon Jul 11 13:53:32 2011 +0000
Revision:
1:b56440e55747
Parent:
0:37bc70ca825c
Child:
2:62e168aedc9a
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 1:b56440e55747 10 void trig(){ //function to call upon interrupt
d_worrall 0:37bc70ca825c 11 db.locate(0);
d_worrall 1:b56440e55747 12 db.printf("%06d", t.read_ms()); //print current time reading
d_worrall 0:37bc70ca825c 13 if(b == false){
d_worrall 1:b56440e55747 14 t.start(); //start timer
d_worrall 0:37bc70ca825c 15 b = true;
d_worrall 0:37bc70ca825c 16 } else {
d_worrall 1:b56440e55747 17 t.stop(); //stop timer
d_worrall 1:b56440e55747 18 db.printf("06d", t.read_ms()); //print out stopwatch time in milliseconds
d_worrall 1:b56440e55747 19 t.reset(); //reset and restart timer
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 1:b56440e55747 26 db.init(); //ALWAYS initialise the dispBoB
d_worrall 0:37bc70ca825c 27 db.cls(); //clear screen
d_worrall 1:b56440e55747 28 trigger.rise(&trig); //attach count() to interrupt on rising edge of trigger
d_worrall 0:37bc70ca825c 29
d_worrall 1:b56440e55747 30 db.printf("%06d", t.read_ms()); //print initial time reading (000000)
d_worrall 0:37bc70ca825c 31
d_worrall 0:37bc70ca825c 32 }