You can check out the source code at the Argonaut Industries Github repository.
The accelerometer is similar to the tilt sensor in a smartphone. It measures the acceleration of the ball, and reports it to the Trinket microcontroller, which controls the color of each of the lights. There's a surprising amount of math needed to calculate the colors, but the postage-stamp-sized Trinket is more than capable.
What Is It?
Argonaut Industries is revolutionizing the field of throwable electronics with the G Ball.
The G Ball is a Nerf-style soccer ball studded with lights which respond to the motion of the ball. When held in your hand, the lights are yellow on the top of the ball, green on the bottom, regardless of how you rotate the ball. When the ball is in free-fall (flying through the air, for instance), the lights turn blue. When the ball experiences a sudden acceleration (when being thrown or caught), the lights flash red.
The G Ball includes a lithum rechargeable battery, and can be recharged over a USB connection.
How Does It Work?The G Ball contains the following electronics:
Building the G Ball
The G Ball is a little tricky to build. The Neopixels are designed to be strung together in a long chain, connected by three wires for power, ground, and data. So we need a continuous chain of wire wrapping around the ball twice, passing through the pixels on each of the black spots on the ball. But the ball is intended to be thrown, bounced, and played with. We can't wrap the wires around the outside, they'll look ugly and snag on things.
The secret is bamboo skewers. I push a skewer through the foam meat of the ball, from one black spot to the next, then use that as a guide to thread a short length of ribbon cable through the inside of the ball. The Neopixels are then soldered to the cables, and then taped down with a piece of black electrical tape, which blends in nicely with the black spots.
The rest of the electronics is buried inside the ball. I cut a large slit in the bottom of the ball with a chef's knife, wide enough to hold the battery pack, charger, microcontroller, accelerometer, and wiring. It's crucial that the accelerometer be placed at the exact center of the ball, exactly aligned with the ball's equator and poles. If it's not aligned right, the positions of the LEDs won't match the values in the computer code. If the accelerometer is off center, it will feel a large acceleration when the ball is spinning.
All told, there are dozens of wires running around the inside of the ball, and even more solder connections. But all that unsightly wiring and electronics is buried inside the foam, where it's invisible and protected from bumps and bruises. I wouldn't recommend throwing the ball against a brick wall too hard, but it's durable enough to stand up to a little game of catch.