Hey folks,
I have made a 4 Lane Lap counter for 1/32 slot cars. Everything works... almost. First I will explain how it works. Then I will explain my problem and what I think could be wrong.
HOW IT WORKS:
The design is basically a "light bridge" where LEDs shine down onto the track illuminating a photoresistor that provides analog input as the shadow of the car passes over it, thus counting a lap. There is a 4x20 LCD screen for display, a few buttons for user inputs, and a set of four countdown LEDs on top (Red, Red, Yellow, Green).
The Code:
In the setup{}:
Prior to the race there are some menus that interact with buttons to allow the racers to choose how many laps the race will be. Then they are prompted to calibrate the analog inputs by placing their cars on the track over the sensors. The racers are prompted to press a button when ready. Then there is a visual countdown via LEDs on top of the light bridge (start/finish) that will signify the start of the race. Once the green one is illuminated, the race begins.
In the loop{}:
I use the map() function on the voltage output of the photoresistors and a convenient cut-off to see whether or not the car has passed over. During the race, the LCD displays a count-down for each lane's laps remaining, and checks each lane to see if it's racer has finished. Placings after the race end are displayed as the car finishes.
I've posted code below, if you care to look. The code works.
HERE'S the problem:
As I said the code works, but only in testing. Under race conditions, the cars are moving very fast and only over the photoresistors for a fraction of a second. Often times if the car is moving at race speeds, the lap will not be counted. At slower speeds every lap will be counted.
My thoughts for possible reasons:
A.) There's a coding problem: Due to my lack of experience, my code is clunky and not optimized causing the AnalogRead() not to poll the pins frequently enough to pick up the car.
B.) The photoresistor isn't having enough chance to drop the voltage as the car passes over.
C.) The unknown unknown.
I've been working on it for months now, and I just bought some photodiodes to test hypothesis B, but in writing I was thinking about just commenting all the code that deals with anything OTHER than a single lane's count and display to test hypothesis A. If y'all think it's hopeless, it'd be a relief I think and I can chuck the whole proj. Any thoughts would be welcomed.
Many thanks,
G
