Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: dispBoB mbed PCA9635
Diff: counter.cpp
- Revision:
- 1:f04131cae8b8
- Parent:
- 0:dd684fb95312
- Child:
- 2:bb7e46464d17
diff -r dd684fb95312 -r f04131cae8b8 counter.cpp
--- a/counter.cpp Mon Jul 11 13:41:08 2011 +0000
+++ b/counter.cpp Mon Jul 11 13:57:07 2011 +0000
@@ -5,23 +5,22 @@
InterruptIn trigger(p12); //set up the trigger as an external interrupt
Timer t;
-void up(){ //function to call upon interrupt
- t.start();
+void up(){ //call this on rising edge
+ t.start(); //start timer
}
-void down(){
- t.stop();
+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();
- t.start();
+ t.reset(); //reset timer
}
int main() {
trigger.mode(PullUp); //activate internal pull up (hardware specific)
- db.init();
+ db.init(); //again ALWAYS initialise dispBoB
db.cls(); //clear screen
- trigger.rise(&up); //attach count() to interrupt on rising edge of trigger
- trigger.fall(&down);
+ 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"
}