## Week 3 Lab & Pet Trick

This week, with the newfound glories of Ohm’s Law and so forth, I feel pulled in many directions. I got Code by Charles Petzold from the library and have been toying with the idea of building a 4 or 8 bit computer. On the other hand, I am starting to think about the final project and how I should start working with gyros, accelerometers and LCDs as most of my ideas so far for this project involve one or all of these components. From everything I’ve been reading, it seems that the latter will require a bit of the former in order to work smoothly and so my intention now is to pursue the best of both worlds… the classics and the modern.

As a pet trick, I’ve been working on making a calculator that converts from integers to binary, handles (at least) addition and subtraction, and then converts back to integer form. Converting from integer to binary is a simple procedure. In binary, we have the following columns: . We take our integer and start at the left column. If the integer (let’s say 129) is greater than or equal to the value of the first column, we turn that column ON, then subtract the column value from our integer (129-128 = 1) and then move to the next column. Since the next column (64) is greater than our remainder of 1, we keep moving forward. In the case of this example, we keep moving forward until we reach the 1’s column. We turn that column ON and then our remainder is 0, so we’re done.Since we’ve been on such a potentiometer kick, I decided that the input mechanisms for my calculator would be two potentiometers. This is a bit tricky because the analog values coming from a potentiometer are not totally static and its hard to get the exact value you want. I experimented with mean and median-based methods of “smoothing” the analog input. However, it was a mode-based approach that ultimately worked best for me because this tends to give the most stable (or recurrent) value as opposed to the most central value as is given by the median. Even so, a potentiometer is not exactly the ideal input medium for a numeric value. Below is the source code for a single potentiometer integer to binary converter and display. More on this “pet trick” to come…
Integer to Binary Potentiometer Display Processing Sketch