Kyle Zampaglione
/
SlotSensorsTest
Code for Slot Sensor readout. Prints to text file on mbed.
main.cpp@4:9ea938dc72f8, 2013-07-04 (annotated)
- Committer:
- kzampag
- Date:
- Thu Jul 04 00:35:19 2013 +0000
- Revision:
- 4:9ea938dc72f8
- Parent:
- 3:a93f3494e6c1
- Child:
- 5:7e1dcb3904dd
Switch to pin 5 and 6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kzampag | 0:6aa040f8bf2c | 1 | #include "mbed.h" |
kzampag | 0:6aa040f8bf2c | 2 | |
kzampag | 0:6aa040f8bf2c | 3 | Serial pc(USBTX, USBRX); // tx, rx |
kzampag | 0:6aa040f8bf2c | 4 | |
kzampag | 0:6aa040f8bf2c | 5 | |
kzampag | 4:9ea938dc72f8 | 6 | DigitalIn sensor1(p5); |
kzampag | 4:9ea938dc72f8 | 7 | DigitalIn sensor2(p6); |
kzampag | 3:a93f3494e6c1 | 8 | LocalFileSystem local("local"); |
kzampag | 0:6aa040f8bf2c | 9 | |
kzampag | 0:6aa040f8bf2c | 10 | Timer t; |
kzampag | 2:c789547682d8 | 11 | int change = 0; |
kzampag | 3:a93f3494e6c1 | 12 | int count = 0; |
kzampag | 3:a93f3494e6c1 | 13 | const int endcount = 10; |
kzampag | 0:6aa040f8bf2c | 14 | |
kzampag | 0:6aa040f8bf2c | 15 | |
kzampag | 0:6aa040f8bf2c | 16 | int main() |
kzampag | 0:6aa040f8bf2c | 17 | { |
kzampag | 0:6aa040f8bf2c | 18 | pc.printf("Break sensor to start timer \n \r"); |
kzampag | 3:a93f3494e6c1 | 19 | FILE *fp = fopen("/local/test.txt", "w"); |
kzampag | 3:a93f3494e6c1 | 20 | while(1) { |
kzampag | 2:c789547682d8 | 21 | |
kzampag | 2:c789547682d8 | 22 | |
kzampag | 2:c789547682d8 | 23 | if (change == 0 && sensor1) { |
kzampag | 2:c789547682d8 | 24 | change = 1; |
kzampag | 2:c789547682d8 | 25 | t.reset(); |
kzampag | 2:c789547682d8 | 26 | t.start(); |
kzampag | 2:c789547682d8 | 27 | pc.printf("Start \n \r"); |
kzampag | 2:c789547682d8 | 28 | } |
kzampag | 0:6aa040f8bf2c | 29 | |
kzampag | 0:6aa040f8bf2c | 30 | |
kzampag | 2:c789547682d8 | 31 | if (change && sensor2) { |
kzampag | 2:c789547682d8 | 32 | t.stop(); |
kzampag | 2:c789547682d8 | 33 | pc.printf("End. Time taken was %f seconds \n \r", t.read()); |
kzampag | 2:c789547682d8 | 34 | change = 0; |
kzampag | 4:9ea938dc72f8 | 35 | fprintf(fp, "%f \n", t.read()); |
kzampag | 3:a93f3494e6c1 | 36 | count++; |
kzampag | 3:a93f3494e6c1 | 37 | } |
kzampag | 3:a93f3494e6c1 | 38 | if (count==endcount) { |
kzampag | 3:a93f3494e6c1 | 39 | pc.printf("Done"); |
kzampag | 3:a93f3494e6c1 | 40 | fclose(fp); |
kzampag | 3:a93f3494e6c1 | 41 | return 0; |
kzampag | 3:a93f3494e6c1 | 42 | |
kzampag | 2:c789547682d8 | 43 | } |
kzampag | 2:c789547682d8 | 44 | |
kzampag | 0:6aa040f8bf2c | 45 | |
kzampag | 0:6aa040f8bf2c | 46 | } |
kzampag | 0:6aa040f8bf2c | 47 | } |