Kyle Zampaglione
/
SlotSensorsTest
Code for Slot Sensor readout. Prints to text file on mbed.
main.cpp@2:c789547682d8, 2013-07-02 (annotated)
- Committer:
- kzampag
- Date:
- Tue Jul 02 22:44:08 2013 +0000
- Revision:
- 2:c789547682d8
- Parent:
- 0:6aa040f8bf2c
- Child:
- 3:a93f3494e6c1
First working copy
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 | 0:6aa040f8bf2c | 6 | DigitalIn sensor1(p11); |
kzampag | 0:6aa040f8bf2c | 7 | DigitalIn sensor2(p12); |
kzampag | 0:6aa040f8bf2c | 8 | |
kzampag | 0:6aa040f8bf2c | 9 | Timer t; |
kzampag | 0:6aa040f8bf2c | 10 | Timer timer1; |
kzampag | 2:c789547682d8 | 11 | int change = 0; |
kzampag | 0:6aa040f8bf2c | 12 | |
kzampag | 0:6aa040f8bf2c | 13 | |
kzampag | 0:6aa040f8bf2c | 14 | int main() |
kzampag | 0:6aa040f8bf2c | 15 | { |
kzampag | 0:6aa040f8bf2c | 16 | pc.printf("Break sensor to start timer \n \r"); |
kzampag | 2:c789547682d8 | 17 | |
kzampag | 0:6aa040f8bf2c | 18 | while(1) { |
kzampag | 2:c789547682d8 | 19 | |
kzampag | 2:c789547682d8 | 20 | if (change == 0 && sensor1) { |
kzampag | 2:c789547682d8 | 21 | change = 1; |
kzampag | 2:c789547682d8 | 22 | t.reset(); |
kzampag | 2:c789547682d8 | 23 | t.start(); |
kzampag | 2:c789547682d8 | 24 | pc.printf("Start \n \r"); |
kzampag | 2:c789547682d8 | 25 | } |
kzampag | 0:6aa040f8bf2c | 26 | |
kzampag | 0:6aa040f8bf2c | 27 | |
kzampag | 2:c789547682d8 | 28 | if (change && sensor2) { |
kzampag | 2:c789547682d8 | 29 | t.stop(); |
kzampag | 2:c789547682d8 | 30 | pc.printf("End. Time taken was %f seconds \n \r", t.read()); |
kzampag | 2:c789547682d8 | 31 | change = 0; |
kzampag | 2:c789547682d8 | 32 | } |
kzampag | 2:c789547682d8 | 33 | |
kzampag | 0:6aa040f8bf2c | 34 | |
kzampag | 0:6aa040f8bf2c | 35 | } |
kzampag | 0:6aa040f8bf2c | 36 | } |