A working prototype - Hourglass Project - Part 4

Read Part 3 first

The summary update is that I have a working hourglass prototype that delivers the basic requirements.

Since the last update, the code changed considerably. Certain nice object-oriented concepts went away, bit packing and elimination of anything that can be replaced or reused from existing objects resulted in the code footprint to shrink to less than half the original size that was working on the PC. This allowed for a successful compile and upload to Arduino.

To give an example, the project code has 3 main objects, a Locations object that models all possible LED locations that can be lit, and an array of Ball objects that fall based on input from a basic gravity object representing earth's gravity. In the original code each Ball object was registering itself to gravity as a listener for any changes in gravity, and gravity would update the value as sensor readings change. When you have ~90 Balls just the fact that each ball has 2 members for gravity value (x & y) would consume 90x2 bytes minimally. So in the current version Balls do not have their own gravity values they are exposed to, instead just 1 Locations object is aware of gravity which amounts to 188 bytes savings just by this change (~10% of Arduino UNO's RAM). Together with other changes, like object states being kept as bits rather than booleans/ints resulted in an Arduino loadable running code. A single Ball object shank from the original fat 21 bytes to merely 6 bytes in the last version.

When the first version of the arduino compilable code was loaded to arduino, it was very nice to see the balls fall, but the progress was slow, really really slow :) (see the video below)

After that it was time to dig into the LedControl library which I did not know how to use beyond lighting up a single LED. It turns out, it has a row level set-on/off function. Too bad LedControl does not have matrix level control to set on/off, it would be even faster. Simply using the row level set on/off call and linking the tilt sensor readings via an analog pin reading resulted in what I call version.07 :) - See the video below.

Will it continue beyond this? Maybe yes.

Read part 5

comments powered by Disqus