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

Dependencies:   DebounceIn mbed

Committer:
kzampag
Date:
Tue Jul 02 22:31:03 2013 +0000
Revision:
0:6aa040f8bf2c
Child:
1:b057042a9427
Child:
2:c789547682d8
Pre-debounce

Who changed what in which revision?

UserRevisionLine numberNew 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 0:6aa040f8bf2c 11 Timer timer2;
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 0:6aa040f8bf2c 17
kzampag 0:6aa040f8bf2c 18 while(1) {
kzampag 0:6aa040f8bf2c 19 if (sensor1) {
kzampag 0:6aa040f8bf2c 20 timer1.start();
kzampag 0:6aa040f8bf2c 21 if (timer1.read_ms()>500) {
kzampag 0:6aa040f8bf2c 22 t.reset();
kzampag 0:6aa040f8bf2c 23 t.start();
kzampag 0:6aa040f8bf2c 24 pc.printf("Start \n \r");
kzampag 0:6aa040f8bf2c 25 timer1.reset();
kzampag 0:6aa040f8bf2c 26 }
kzampag 0:6aa040f8bf2c 27
kzampag 0:6aa040f8bf2c 28 } // end sensor 1
kzampag 0:6aa040f8bf2c 29
kzampag 0:6aa040f8bf2c 30
kzampag 0:6aa040f8bf2c 31 if (sensor2) {
kzampag 0:6aa040f8bf2c 32 timer1.reset();
kzampag 0:6aa040f8bf2c 33 timer1.start();
kzampag 0:6aa040f8bf2c 34 if (timer1.read_ms()>500) {
kzampag 0:6aa040f8bf2c 35 t.stop();
kzampag 0:6aa040f8bf2c 36 pc.printf("End. Time taken was %f seconds \n \r", t.read());
kzampag 0:6aa040f8bf2c 37 }
kzampag 0:6aa040f8bf2c 38
kzampag 0:6aa040f8bf2c 39 } // end sensor2
kzampag 0:6aa040f8bf2c 40
kzampag 0:6aa040f8bf2c 41 }
kzampag 0:6aa040f8bf2c 42 }