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.

Files at this revision

API Documentation at this revision

Comitter:
mdu7078
Date:
Mon May 13 16:24:58 2013 +0000
Parent:
0:bcdc97617c5d
Commit message:
Ending line complete.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Apr 20 18:31:09 2013 +0000
+++ b/main.cpp	Mon May 13 16:24:58 2013 +0000
@@ -8,23 +8,77 @@
  * * * * * * * * * * * * * * * * * * * * * * * * * * */
 #include "mbed.h"
 
+/* This is a print button that allows the time to be outputted */
+DigitalIn button(p30);
+
+/* Tells when to stop the timer */
+int end1 = 0;
+int end2 = 0;
+
+/* Rise detection */
+int rise = 0;
+
+/* Create two individual timers */
+Timer t1;
+Timer t2;
+
+/* Recieving pin */
+InterruptIn rxo(p10);
+
 /* Interrupt sensors */
 InterruptIn sEnd1(p20);
 InterruptIn sEnd2(p21);
 
 /* Indicator LEDs */
-DigitalOut iled1(LED1);
-DigitalOut iled2(LED2);
+DigitalOut iled1(p22);
+DigitalOut iled2(p23);
+
+/* Status LEDs */
+DigitalOut sled1(LED1);
+DigitalOut sled2(LED2);
+DigitalOut sled3(LED3);
+DigitalOut sled4(LED4);
+
+/* Winner LEDs */
+DigitalOut wled11(p11);  // Gate 1 Win
+DigitalOut wled12(p12);  // Gate 1 Win
+DigitalOut wled13(p13);  // Gate 1 Win
+DigitalOut wled21(p36);  // Gate 2 Win
+DigitalOut wled22(p35);  // Gate 2 Win
+DigitalOut wled23(p34);  // Gate 2 Win
 
 /* Tells when there is a winner */
 int win = 0;
 
+/* Pulsed recieving */
+int rxc = 0;
+
+/* This detects a transmitted signal */
+void recieve(){
+    if (rxc >= 1){
+        /* Set status LEDs */
+        sled2 = 1;
+        sled3 = 1;
+        
+        /* Start timers */
+        t1.start();
+        t2.start();
+    }
+    rxc += 1;
+}
+
 /* This detects interrupt 1 */
 void l1(){
     if (win == 0){
         iled1 = 1;
         win = 1;
+        wled11 = 1;
+        wled12 = 1;
+        wled13 = 1;
     }
+    end1 = 1;
+    sled1 = 1;  // Set status LED
+    t1.stop();  // Stop timer 1
 }
 
 /* This detects interrupt 2 */
@@ -32,19 +86,68 @@
     if (win == 0){
         iled2 = 1;
         win = 1;
+        wled21 = 1;
+        wled22 = 1;
+        wled23 = 1;
     }
+    end2 = 1;
+    sled4 = 1;  // Set status LED
+    t2.stop();  // Stop timer 2
 }
 
 int main() {
     /* Set the LEDs off */
     iled1 = 0;
     iled2 = 0;
+    sled1 = 0;
+    sled2 = 0;
+    sled3 = 0;
+    sled4 = 0;
+    wled11 = 0;
+    wled12 = 0;
+    wled13 = 0;
+    wled21 = 0;
+    wled22 = 0;
+    wled23 = 0;
     
     /* Attach interrupt service routine to pins */
     sEnd1.fall(&l1);
     sEnd2.fall(&l2);
+    rxo.rise(&recieve);
     
+    printf("Ready!\n\r");
     while(1) {
-        //Do nothing
+        if (button.read() == 1 && rise == 0){
+            /* Set rise detector to high */
+            rise = 1;
+            
+            /* Check Track 1 */
+            if (end1 == 1){
+                printf("========== Track 1 Time ==========\n\r");
+                printf(" Finished in: %lf seconds\n\r", t1.read());
+                printf("==================================\n\r\n\r"); 
+            }
+            else {
+                printf("Track 1 has not finished\n\r\n\r");   
+            }
+            
+            /* Check Track 2 */
+            if (end2 == 1){
+                printf("========== Track 2 Time ==========\n\r");
+                printf(" Finished in: %lf seconds\n\r", t2.read());
+                printf("==================================\n\r\n\r"); 
+            }
+            else {
+                printf("Track 2 has not finished\n\r\n\r");   
+            }
+        }
+        else if (button.read() == 0 && rise == 1){
+            /* Reset rise detection */
+            rise = 2;
+            wait (0.001); //Debounce
+        }
+        else if (button.read() == 0 && rise == 2){
+            rise = 0;
+        }
     }
 }