![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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.
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.
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.
Diff: main.cpp
- Revision:
- 0:bcdc97617c5d
- Child:
- 1:d7651ce5d59b
diff -r 000000000000 -r bcdc97617c5d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Apr 20 18:31:09 2013 +0000 @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * + * This detects a winner in a two person race by * + * detecting when there is a break in the signal * + * sent to two different pins. When the winner is * + * detected, the corresponding LED is lit. * + * * + * Created by: Michael Dushkoff (mad1841@rit.edu) * + * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#include "mbed.h" + +/* Interrupt sensors */ +InterruptIn sEnd1(p20); +InterruptIn sEnd2(p21); + +/* Indicator LEDs */ +DigitalOut iled1(LED1); +DigitalOut iled2(LED2); + +/* Tells when there is a winner */ +int win = 0; + +/* This detects interrupt 1 */ +void l1(){ + if (win == 0){ + iled1 = 1; + win = 1; + } +} + +/* This detects interrupt 2 */ +void l2(){ + if (win == 0){ + iled2 = 1; + win = 1; + } +} + +int main() { + /* Set the LEDs off */ + iled1 = 0; + iled2 = 0; + + /* Attach interrupt service routine to pins */ + sEnd1.fall(&l1); + sEnd2.fall(&l2); + + while(1) { + //Do nothing + } +}