Tuesday, December 3, 2013

Coding Update

Before receiving parts this upcoming lab session, we put together some prototype code for the device. Rather than use three push-buttons to control the Red, Green, and Blue lights/ films, we decided to try potentiometers. This simplifies the coding in that instead of having an often imperfect debounce function, we have "off" and "on" portions of the potentiometer's range.

Furthermore, if we manage to get the dual-Arduino interface working then we will be able to use the analog-input pins from the potentiometers in conjunction with PWM pins going to the RGB LED. As one or more of the servo-motors rotate the films into the light, we could have the RGB LED fade in or out simultaneously. This would really only bring aesthetic value.

As we have it now, the LCD-screen (running in 4-bit mode due to I/O constraints) uses too many PWM pins for this to be possible- especially because the servo motors require PWM as well.

There are a few features we would like to consider exploring and expanding such as this LED- fader function. We'll talk about these more in the next post.


Here we have the working code. We made heavy use of arrays, because most of the time we were manipulating three variables- one corresponding to red, green and blue. Not only did this simplify and streamline our code, but it allowed us to use for-loops. This cut down on the size of the sketch and will make debugging much easier.

Next, we used multiple "switch" statements. We shied away from if-else statements, because the variables are very well constrained and defined and therefore fit 'cases' rather than conditions. In Java, using 'break' statements is considered sloppy coding, but this simplifies our code enough that it doesn't matter.
Finally, we condensed much of our coding into subfunctions and wrote many of our given values as variables. This de-clutters the main loop, simplifies future adjustments and overall makes the code much more modular. Here is what we have:

No comments:

Post a Comment