123

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
joaomazza
Date:
Sat Sep 29 19:14:08 2018 +0000
Commit message:
d

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
diff -r 000000000000 -r caf81a29d035 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Sep 29 19:14:08 2018 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+#define NUM_COUNTS 2
+ 
+InterruptIn button(PB_9);
+DigitalOut simulation(PA_8);
+int count;
+float t1 = 0, total = 0, RPM;
+Timer t;
+Serial pc(PA_9, PA_10); // tx and rx
+ 
+void flip() {
+    t.start();
+    count++;
+    total += t.read_ms() - t1;
+    t1 = t.read_ms();
+}
+ 
+int main() {
+    button.rise(&flip);  // attach the address of the flip function to the rising edge
+    while(1) {           // wait around, interrupts will interrupt this!
+        if(count >= NUM_COUNTS){
+            t.stop();
+            RPM = ((NUM_COUNTS-1)/(total/1000))*60;
+            pc.printf("%.2f\n",RPM);
+            count = 0;
+            t1 = 0;
+            total = 0;
+            t.reset();
+            }   
+            simulation = 0;
+            wait_ms(24);
+            simulation = 1;
+            wait_ms(1);
+            }
+    }
\ No newline at end of file
diff -r 000000000000 -r caf81a29d035 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Sep 29 19:14:08 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file