Hey guys. I'm going to share with you my code for my Rainfall simulator.

Hey guys. I’m going to share with you my code for my Rainfall simulator. Currently I’m using 2 neopixel 60 led/m strands inside of my Rosewill Throne case, with my leds being powered by my PSU. Originally I was using an Arduino Uno to control it, but it seemed to slow for me. I switched over to an Arduino Due and it still seems slightly slow. If anyone has any suggestions or improvements on the simulator, I’d love to hear them. I’m using commit cd982478a9 of the 3.1 branch.

How it works/is supposed to work:

The way I laid out my LEDs, my first one begins about 3/5 of the way on the right side of my case, then loops around to have the last LED land on the first one. Rainfall is determined based on the heaviness value, the bigger it is, the faster and more likely new drops are to appear. Rain starts “falling” from the very center LED at the top of my case (not the center LED in the strip). I randomly determine whether it falls left or right.

As the leds “fall,” I’m checking to see if the next spot they move into, will be the “pool.” The pool is the collection of droplets starting from the very center point of the case, it will slowly fill up to simulate the case being filled with water from the rain. In order to keep the “water level” balanced, I just use a boolean and right/left counts that keep track of whether or not the droplet is going to be added to the right or left side of the pool. If one side of the pool is higher, or will be higher, than the other, then the droplet will be added to the opposing side to keep it balanced. Once a certain number of droplets are contained in the pool, it will reset and determine a new heaviness.

I’m planning on adding a lightning simulator to it as well, that will generate bolts of lightning (as white LEDs) that will start at the top and angle along the sides and have them flash, but I won’t attempt it until I can solve the slow down issue that I’m observing. I’ve tried to optimize the code as much as possible, but it’d be really helpful to have an extra set of eyes and minds to help me solve this.

Link to the source - http://pastebin.com/7z5HjLtR
http://www.youtube.com/watch?v=wI4OUHlIocs