Code for Slot Sensor readout. Prints to text file on mbed.

Dependencies:   DebounceIn mbed

main.cpp

Committer:
kzampag
Date:
2013-07-03
Revision:
3:a93f3494e6c1
Parent:
2:c789547682d8
Child:
4:9ea938dc72f8

File content as of revision 3:a93f3494e6c1:

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx


DigitalIn sensor1(p11);
DigitalIn sensor2(p12);
LocalFileSystem local("local");

Timer t;
int change = 0;
int count = 0;
const int endcount = 10;


int main()
{
    pc.printf("Break sensor to start timer \n \r");
    FILE *fp = fopen("/local/test.txt", "w");
    while(1) {


        if (change == 0 && sensor1) {
            change = 1;
            t.reset();
            t.start();
            pc.printf("Start \n \r");
        }


        if (change && sensor2) {
            t.stop();
            pc.printf("End. Time taken was %f seconds \n \r", t.read());
            change = 0;
            fprintf(fp, "%f \n \r", t.read());
            count++;
        }
        if (count==endcount) {
            pc.printf("Done");
            fclose(fp);
            return 0;

        }


    }
}