senior design

Dependencies:   mbed

Fork of Test1 by Martin Ofalt Jr.

main.cpp

Committer:
powerstrokediesel97
Date:
2010-12-02
Revision:
0:1da3cc3bc3a5

File content as of revision 0:1da3cc3bc3a5:

#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);
    }
}