Kyle Zampaglione
/
SlotSensorsTest
Code for Slot Sensor readout. Prints to text file on mbed.
main.cpp
- Committer:
- kzampag
- Date:
- 2013-07-08
- Revision:
- 5:7e1dcb3904dd
- Parent:
- 4:9ea938dc72f8
- Child:
- 6:360247c0c7df
File content as of revision 5:7e1dcb3904dd:
#include "mbed.h" Serial pc(USBTX, USBRX); // tx, rx DigitalIn sensor1(p5); DigitalIn sensor2(p6); LocalFileSystem local("local"); Timer t; int change = 0; int count = 1; 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: Count= %d \n \r", count); } if (change && sensor2) { t.stop(); pc.printf("End. Time taken was %f seconds \n \r", t.read()); change = 0; fprintf(fp, "%f \n", t.read()); count++; } if (count>endcount) { pc.printf("Done"); fclose(fp); return 0; } if (pc.readable()) { char c = pc.getc(); if(c == 'e') { pc.printf("Program terminated"); return 0; } } } }