Ball rolling LED signal light

Hi Everyone!

I’ve worked through a number of the tutorials, and am now going to start out on my first project.

Here’s the idea:

I have a pipe with three switches placed at the beginning, middle and end of the pipe. There’s a tri-color light bar (8 RGB LEDs and a 595 shift register) at the beginning of the pipe. The light is by default set to blinking green. As a ball rolls down the pipe, the first sensor will change the light colour to solid red. If it reaches the second sensor in less than 2 seconds, the light changes back to blinking green. If it takes longer than 2 seconds, the light stays red until the ball reaches the sensor at the end of the pipe. When the ball reaches the end sensor the light switches to green.

Future, I’d like to output to an LCD how long it took for the ball to go from the top of the pipe to the bottom.

The idea is for the light to tell me when it’s safe to put another ball in the pipe. If it’s rolling fast enough, I can potentially have two balls in the pipe at the same time, so I’d have to “track” the time each ball takes even though the second ball might be in play before the first leaves the pipe.

So my big question is, can someone help me get started? I just can’t think of where to start (my brain kinda gets this, but isn’t thinking "out-side the box just yet).

Thanks so much for your thoughts!
Sarah :slight_smile:

Well, you'll likely want to store the time the ball(s) enter the pipe in an array, so you can have multiple balls in the pipe.
Then you'd remove the first time from the ball-in-pipe array when a ball leaves, dropping the remaining balls in the array down a position.

As for driving the LED's, I'd suggest looking into the Blink Without Delay example, you'll want to drive your LED's in this fashion, to not interfere with the sensors.

Another thing you might want to look into is interrupts, to be precise, to use an interrupt when your sensor(s) get tripped.
This could be done by timely polling your sensors aswell, depending on your mechanical setup.

Hope this helped =)