Interactive Rotating Earth and Sun
by mcconnbb in Circuits > Microcontrollers
115 Views, 1 Favorites, 0 Comments
Interactive Rotating Earth and Sun
The accelerometer on the Circuit Playground Bluefruit is incredibly versatile, and one powerful way to make use of it is sensing direction of tilt. I implemented it with a disc and a couple balls to simulate how the earth rotates around the sun. As you tilt the disc and move the "earth", the LED strip moves through a gradient of colors to simulate the seasons, and a speaker plays sounds that correspond to that season. Another LED strip is also pulsing to imitate stars around the vast space.
I had originally planned on making the ping pong ball rotate with a continuous rotation servo motor instead of tilting, but found that the tilting leading to the changing gradient was much more satisfying and interactive.
Supplies
- Circuit Playground Bluefruit
- USB Data cable
- One 30 light LED strip
- One 20 light LED strip
- Speaker
- Laser cutter
- 12 x 24 x .25 inch sheet of purple acrylic
- Ping pong ball
- Stress ball
- 5 alligator clips
- Super glue
- Triple A battery pack
Create the Discs
Create a simple circle with a 6 inch radius in Adobe Illustrator. Add a much smaller circle, a little smaller than your stress ball, in the very middle. Then, add a couple small rectangles, approximately 1 by 2 inches, near the middle. This will serve as the base. Then, for the rails, copy and paste the design into another Illustrator file. For this one, add a second circle approximately 11 inches in diameter with the same center as the big one. Then, add another circle, about 9 inches in diameter, also centered around the middle. These will serve as the rails for your ping pong ball as it rotates around the stress ball. Then, cut your designs using the acrylic sheet listed above with a laser cutter.
Attach the Discs Together
Usually, when connecting acrylic, welding with acrylic adhesive is the strongest option. However, it doesn't fit well for this project as acrylic adhesive is usually for connecting corners, while the discs in this case need to be stacked vertically. Super glue works just fine as not much stress will be applied to the design. Simply apply some to the outer edges of the bottom disc and add the outer rail. Then do the same for the inner section of the design.
Pick Your Audio Files
It's fairly easy to find free to use audio files online with ambient sounds. I picked some that I felt best embodied the seasons, with a strong breeze for the winter, birds chirping for the spring, cicadas for the summer, and leaves crunching for autumn. You can download them in either .MP3 or .wav format, but getting them in MP3 will require an extra step. I found pixabay to work well for this, and I simply searched the name of the season for each.
Prepare the Audio Files
The CPB audio libraries used in this project require .wav files in 16-bit mono format with a 22KHz or lower sample rate. The files you found online likely won't match this format. To fix this, you need to use Audacity or another sound editing program. I followed the steps explained here on the Adafruit website. The basic steps involve mixing the stereo down to mono, converting the file to 16-bit format, changing the project rate to below 22KHz, and resampling with that rate. Once this is done, save the file to a folder on your CPB. I named mine "seasons".
Prepare the Code
The code for this project is centered around four functions, one for each season, that is called based on the tilt of the accelerometer. The program takes the x and y outputs of the accelerometer and compares them to figure out how the discs are tilted. I then squared the ratio to get more change in color in the middle of the seasons. The code also makes use of the Fancy LED library, which allows for automatically generated gradients. I normalize the values given by the accelerometer and feed them into the range of the gradient that corresponds to that season. I had originally attempted to code the gradient myself, but found that it was difficult to get the gradient to go smoothly. A huge advantage of the Fancy LED library is that it allows for gamma correction, which helps your eyes follow the transitions between colors better. You can read more about it on the Adafruit website. Finally, for the stars, I utilized the SparklePulse from the Adafruit_LED_Animations library, which matched what I wanted to see from the stars.
Downloads
Fine Tune the Colors
You will likely find that the colors that show up on your LED strips don't quite match up with their normal RGB values. This is further explained in the Adafruit article in the previous section, but the basic idea is that LED's rapidly switch on and off and it causes our eyes to perceive a different color. This means that finding the colors you desire requires some experimentation. A good starting point is the Adafruit Colors library, which lists colors based on how they are perceived by humans when released from LED's. I also highly recommend modifying the gamma values based on what you like, as these also influence how bright the design is.
Wire Everything Together
All in all, I needed 5 alligator clips for this design. For the longer LED strip, I connected the RED clip (power) to the VOUT port, the WHITE clip (signal) to the A1 port, and the BLACK clip (ground) to one of the ground ports. For the shorter LED strip, I assume the ends of the wires are stripped like mine. I connected the GREEN wire (signal) to A4, the WHITE wire (ground) to any of the ground ports, and the RED wire (power) to the 3.3V port. Finally, for the speaker, I clipped the base to a ground port and the base to A3.
Attach the Pieces to the Discs
Don't worry too much about cleanliness, there's not a great solution to this. I just as much two sided tape as possible to get all of the wires, LED strands, CPB, speaker, and battery pack stuck to discs. Thread the wires through the two rectangles that were previously cut in the acrylic.
Prepare the Balls
The stress ball will resemble the sun and be placed in the center, and the ping pong ball will resemble the earth and rotate around the rails. There's no great way to color either of these, as painting circular objects is incredibly difficult. I covered the stress ball in yellow paper and colored the ping pong ball with marker.
Put Everything Together and Turn It On!
Put the sun on the middle, ping pong ball on the outside rails, and turn on the battery pack and speaker. Here's a demonstration of how mine works.