senior design

Dependencies:   mbed

Fork of Test1 by Martin Ofalt Jr.

Revision:
0:1da3cc3bc3a5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 02 07:21:02 2010 +0000
@@ -0,0 +1,59 @@
+#include "mbed.h"
+
+Serial transmit(p28,p27);
+Timer t;
+InterruptIn risingEdge(p16);
+
+DigitalOut myled(LED1);
+DigitalOut myled2(LED2);
+
+long int count;
+
+//Increment the counter variable
+void pulses() {
+    if(myled2 == 1) {
+        myled2 = 0;
+    } else {
+        myled2 = 1;
+    }
+    count++;
+}
+
+//main program
+int main() {
+
+    risingEdge.rise(&pulses);
+   
+    while(1) {
+       
+      //  myled = 0;
+        
+        t.reset();
+        t.start();
+        count = 0;
+        while(t.read_ms() < 400) {
+            ;
+        }
+       
+        t.stop();
+      //  myled = 1;
+        long int temp = count;
+       // lcdout.putc(0xFE);
+      //  lcdout.putc(0x01);
+      //  lcdout.printf("Count: %d\n", temp);
+     // transmit.printf("Count: %d", temp);
+        double rev = (double)temp/30.0;
+        double sec = 1000.0/(double)t.read_ms();
+        double rps = rev * sec;
+        double rpm = rps*60.0;
+        int irpm = (int)rpm;
+        
+        //lcdout.printf("Speed: %0.2f RPM", rpm);
+      //  transmit.printf(" Speed: %0.2f RPM", rpm);
+      transmit.printf("%d", irpm);
+      //  transmit.putc(0xA);
+        transmit.putc(0xD);
+    }
+}
+
+