This is the ending line gate for a line following race track. The gate receives a signal to start two timers once both cars have left the starting gate and the timers are halted by breaking two corresponding tripwires at the end gate.

Dependencies:   mbed

About

This is a program that is used in determining the race times of two separate line following cars on a track. The program uses a wireless signal that is sent from the starting gate to determine when to start the timers and the timers are stopped by breaking the tripwire at the finish line. The first race car to break a tripwire will have that corresponding gate's LED lights also light up to indicate which car finished first. This is achieved almost entirely through interrupts in which a falling condition is detected for the tripwires and a rising condition is detected for the timer start. The times can also be printed out to a terminal screen by pressing a connected button. Alternatively, the ending gate can work entirely without timing by disregarding the receiving component.

Hardware

The hardware to implement this is fairly straightforward and is shown below. The G and B indicate different colored LEDs (Green and Blue respectively) which are used to determine a winner at the ending gate. /media/uploads/mdu7078/endinggate-1.png

Circuit diagram constructed using CircuitLab.

Usage

The mbed should be reset each time in order to clear the previous timing data. The tripwires should also be reset prior to this reset or else they will register again. The print button can be pressed at any time to print the timing results through a serial connection. If neither car has finished, the display will indicate this, or alternatively once each car has finished, its time will be shown.

Committer:
mdu7078
Date:
Mon May 13 16:24:58 2013 +0000
Revision:
1:d7651ce5d59b
Parent:
0:bcdc97617c5d
Ending line complete.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mdu7078 0:bcdc97617c5d 1 /* * * * * * * * * * * * * * * * * * * * * * * * * * *
mdu7078 0:bcdc97617c5d 2 * This detects a winner in a two person race by *
mdu7078 0:bcdc97617c5d 3 * detecting when there is a break in the signal *
mdu7078 0:bcdc97617c5d 4 * sent to two different pins. When the winner is *
mdu7078 0:bcdc97617c5d 5 * detected, the corresponding LED is lit. *
mdu7078 0:bcdc97617c5d 6 * *
mdu7078 0:bcdc97617c5d 7 * Created by: Michael Dushkoff (mad1841@rit.edu) *
mdu7078 0:bcdc97617c5d 8 * * * * * * * * * * * * * * * * * * * * * * * * * * */
mdu7078 0:bcdc97617c5d 9 #include "mbed.h"
mdu7078 0:bcdc97617c5d 10
mdu7078 1:d7651ce5d59b 11 /* This is a print button that allows the time to be outputted */
mdu7078 1:d7651ce5d59b 12 DigitalIn button(p30);
mdu7078 1:d7651ce5d59b 13
mdu7078 1:d7651ce5d59b 14 /* Tells when to stop the timer */
mdu7078 1:d7651ce5d59b 15 int end1 = 0;
mdu7078 1:d7651ce5d59b 16 int end2 = 0;
mdu7078 1:d7651ce5d59b 17
mdu7078 1:d7651ce5d59b 18 /* Rise detection */
mdu7078 1:d7651ce5d59b 19 int rise = 0;
mdu7078 1:d7651ce5d59b 20
mdu7078 1:d7651ce5d59b 21 /* Create two individual timers */
mdu7078 1:d7651ce5d59b 22 Timer t1;
mdu7078 1:d7651ce5d59b 23 Timer t2;
mdu7078 1:d7651ce5d59b 24
mdu7078 1:d7651ce5d59b 25 /* Recieving pin */
mdu7078 1:d7651ce5d59b 26 InterruptIn rxo(p10);
mdu7078 1:d7651ce5d59b 27
mdu7078 0:bcdc97617c5d 28 /* Interrupt sensors */
mdu7078 0:bcdc97617c5d 29 InterruptIn sEnd1(p20);
mdu7078 0:bcdc97617c5d 30 InterruptIn sEnd2(p21);
mdu7078 0:bcdc97617c5d 31
mdu7078 0:bcdc97617c5d 32 /* Indicator LEDs */
mdu7078 1:d7651ce5d59b 33 DigitalOut iled1(p22);
mdu7078 1:d7651ce5d59b 34 DigitalOut iled2(p23);
mdu7078 1:d7651ce5d59b 35
mdu7078 1:d7651ce5d59b 36 /* Status LEDs */
mdu7078 1:d7651ce5d59b 37 DigitalOut sled1(LED1);
mdu7078 1:d7651ce5d59b 38 DigitalOut sled2(LED2);
mdu7078 1:d7651ce5d59b 39 DigitalOut sled3(LED3);
mdu7078 1:d7651ce5d59b 40 DigitalOut sled4(LED4);
mdu7078 1:d7651ce5d59b 41
mdu7078 1:d7651ce5d59b 42 /* Winner LEDs */
mdu7078 1:d7651ce5d59b 43 DigitalOut wled11(p11); // Gate 1 Win
mdu7078 1:d7651ce5d59b 44 DigitalOut wled12(p12); // Gate 1 Win
mdu7078 1:d7651ce5d59b 45 DigitalOut wled13(p13); // Gate 1 Win
mdu7078 1:d7651ce5d59b 46 DigitalOut wled21(p36); // Gate 2 Win
mdu7078 1:d7651ce5d59b 47 DigitalOut wled22(p35); // Gate 2 Win
mdu7078 1:d7651ce5d59b 48 DigitalOut wled23(p34); // Gate 2 Win
mdu7078 0:bcdc97617c5d 49
mdu7078 0:bcdc97617c5d 50 /* Tells when there is a winner */
mdu7078 0:bcdc97617c5d 51 int win = 0;
mdu7078 0:bcdc97617c5d 52
mdu7078 1:d7651ce5d59b 53 /* Pulsed recieving */
mdu7078 1:d7651ce5d59b 54 int rxc = 0;
mdu7078 1:d7651ce5d59b 55
mdu7078 1:d7651ce5d59b 56 /* This detects a transmitted signal */
mdu7078 1:d7651ce5d59b 57 void recieve(){
mdu7078 1:d7651ce5d59b 58 if (rxc >= 1){
mdu7078 1:d7651ce5d59b 59 /* Set status LEDs */
mdu7078 1:d7651ce5d59b 60 sled2 = 1;
mdu7078 1:d7651ce5d59b 61 sled3 = 1;
mdu7078 1:d7651ce5d59b 62
mdu7078 1:d7651ce5d59b 63 /* Start timers */
mdu7078 1:d7651ce5d59b 64 t1.start();
mdu7078 1:d7651ce5d59b 65 t2.start();
mdu7078 1:d7651ce5d59b 66 }
mdu7078 1:d7651ce5d59b 67 rxc += 1;
mdu7078 1:d7651ce5d59b 68 }
mdu7078 1:d7651ce5d59b 69
mdu7078 0:bcdc97617c5d 70 /* This detects interrupt 1 */
mdu7078 0:bcdc97617c5d 71 void l1(){
mdu7078 0:bcdc97617c5d 72 if (win == 0){
mdu7078 0:bcdc97617c5d 73 iled1 = 1;
mdu7078 0:bcdc97617c5d 74 win = 1;
mdu7078 1:d7651ce5d59b 75 wled11 = 1;
mdu7078 1:d7651ce5d59b 76 wled12 = 1;
mdu7078 1:d7651ce5d59b 77 wled13 = 1;
mdu7078 0:bcdc97617c5d 78 }
mdu7078 1:d7651ce5d59b 79 end1 = 1;
mdu7078 1:d7651ce5d59b 80 sled1 = 1; // Set status LED
mdu7078 1:d7651ce5d59b 81 t1.stop(); // Stop timer 1
mdu7078 0:bcdc97617c5d 82 }
mdu7078 0:bcdc97617c5d 83
mdu7078 0:bcdc97617c5d 84 /* This detects interrupt 2 */
mdu7078 0:bcdc97617c5d 85 void l2(){
mdu7078 0:bcdc97617c5d 86 if (win == 0){
mdu7078 0:bcdc97617c5d 87 iled2 = 1;
mdu7078 0:bcdc97617c5d 88 win = 1;
mdu7078 1:d7651ce5d59b 89 wled21 = 1;
mdu7078 1:d7651ce5d59b 90 wled22 = 1;
mdu7078 1:d7651ce5d59b 91 wled23 = 1;
mdu7078 0:bcdc97617c5d 92 }
mdu7078 1:d7651ce5d59b 93 end2 = 1;
mdu7078 1:d7651ce5d59b 94 sled4 = 1; // Set status LED
mdu7078 1:d7651ce5d59b 95 t2.stop(); // Stop timer 2
mdu7078 0:bcdc97617c5d 96 }
mdu7078 0:bcdc97617c5d 97
mdu7078 0:bcdc97617c5d 98 int main() {
mdu7078 0:bcdc97617c5d 99 /* Set the LEDs off */
mdu7078 0:bcdc97617c5d 100 iled1 = 0;
mdu7078 0:bcdc97617c5d 101 iled2 = 0;
mdu7078 1:d7651ce5d59b 102 sled1 = 0;
mdu7078 1:d7651ce5d59b 103 sled2 = 0;
mdu7078 1:d7651ce5d59b 104 sled3 = 0;
mdu7078 1:d7651ce5d59b 105 sled4 = 0;
mdu7078 1:d7651ce5d59b 106 wled11 = 0;
mdu7078 1:d7651ce5d59b 107 wled12 = 0;
mdu7078 1:d7651ce5d59b 108 wled13 = 0;
mdu7078 1:d7651ce5d59b 109 wled21 = 0;
mdu7078 1:d7651ce5d59b 110 wled22 = 0;
mdu7078 1:d7651ce5d59b 111 wled23 = 0;
mdu7078 0:bcdc97617c5d 112
mdu7078 0:bcdc97617c5d 113 /* Attach interrupt service routine to pins */
mdu7078 0:bcdc97617c5d 114 sEnd1.fall(&l1);
mdu7078 0:bcdc97617c5d 115 sEnd2.fall(&l2);
mdu7078 1:d7651ce5d59b 116 rxo.rise(&recieve);
mdu7078 0:bcdc97617c5d 117
mdu7078 1:d7651ce5d59b 118 printf("Ready!\n\r");
mdu7078 0:bcdc97617c5d 119 while(1) {
mdu7078 1:d7651ce5d59b 120 if (button.read() == 1 && rise == 0){
mdu7078 1:d7651ce5d59b 121 /* Set rise detector to high */
mdu7078 1:d7651ce5d59b 122 rise = 1;
mdu7078 1:d7651ce5d59b 123
mdu7078 1:d7651ce5d59b 124 /* Check Track 1 */
mdu7078 1:d7651ce5d59b 125 if (end1 == 1){
mdu7078 1:d7651ce5d59b 126 printf("========== Track 1 Time ==========\n\r");
mdu7078 1:d7651ce5d59b 127 printf(" Finished in: %lf seconds\n\r", t1.read());
mdu7078 1:d7651ce5d59b 128 printf("==================================\n\r\n\r");
mdu7078 1:d7651ce5d59b 129 }
mdu7078 1:d7651ce5d59b 130 else {
mdu7078 1:d7651ce5d59b 131 printf("Track 1 has not finished\n\r\n\r");
mdu7078 1:d7651ce5d59b 132 }
mdu7078 1:d7651ce5d59b 133
mdu7078 1:d7651ce5d59b 134 /* Check Track 2 */
mdu7078 1:d7651ce5d59b 135 if (end2 == 1){
mdu7078 1:d7651ce5d59b 136 printf("========== Track 2 Time ==========\n\r");
mdu7078 1:d7651ce5d59b 137 printf(" Finished in: %lf seconds\n\r", t2.read());
mdu7078 1:d7651ce5d59b 138 printf("==================================\n\r\n\r");
mdu7078 1:d7651ce5d59b 139 }
mdu7078 1:d7651ce5d59b 140 else {
mdu7078 1:d7651ce5d59b 141 printf("Track 2 has not finished\n\r\n\r");
mdu7078 1:d7651ce5d59b 142 }
mdu7078 1:d7651ce5d59b 143 }
mdu7078 1:d7651ce5d59b 144 else if (button.read() == 0 && rise == 1){
mdu7078 1:d7651ce5d59b 145 /* Reset rise detection */
mdu7078 1:d7651ce5d59b 146 rise = 2;
mdu7078 1:d7651ce5d59b 147 wait (0.001); //Debounce
mdu7078 1:d7651ce5d59b 148 }
mdu7078 1:d7651ce5d59b 149 else if (button.read() == 0 && rise == 2){
mdu7078 1:d7651ce5d59b 150 rise = 0;
mdu7078 1:d7651ce5d59b 151 }
mdu7078 0:bcdc97617c5d 152 }
mdu7078 0:bcdc97617c5d 153 }