Lieven Hollevoet / Mbed 2 deprecated EdgeCounter

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
hollie
Date:
Mon Dec 21 15:38:02 2009 +0000
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 21 15:38:02 2009 +0000
@@ -0,0 +1,51 @@
+// EdgeCounter on mbed
+//
+// Counts falling edges on p5.
+// Used as test setup for interfacing a hall sensor to our water/gas sensor.
+//
+// Whenever the hall sensor triggers, edgecount is incremented and the
+// current value is transmitted to the serial port.
+//
+// Any character sent to the serial port returns the current count value
+//
+// Written by Lieven Hollevoet
+
+#include "mbed.h"
+
+// Create objects
+Serial pc(USBTX, USBRX);
+DigitalOut status(LED4);
+DigitalOut count(LED2);
+InterruptIn sensor(p5);
+
+int edgecount;
+
+void ISR_serial(void) {
+    
+    char tmp = pc.getc();
+    status = 1;
+    
+    pc.printf("Current edge count is %i\r\n", edgecount);
+    status = 0;
+}
+
+void falling_edge(void){
+    edgecount++;
+    count = 1;
+    pc.printf("Falling edge, count is %i!\r\n", edgecount);
+    count = 0;
+}
+
+int main() {
+
+    count     = 0;
+    edgecount = 0;
+    
+    pc.printf("Edgecounter started");
+
+    // Attach interrupt handlers
+    pc.attach(&ISR_serial);
+    sensor.fall(&falling_edge);
+    
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 21 15:38:02 2009 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0