## Binary Calculator

We have just finished our new project: an NXT Binary Calculator built with a single NXT 2.0 kit and some standard 4×2 LEGO bricks (actually, anything with colors will do). We have both designed and programmed the robot (using RobotC).

Here are some pictures of the Calculator:

First of all, to understand how the robot works, you have to know what binary numbers are.

A binary number is written using only two different digits (0, 1) whereas the decimal system uses ten (0 to 9).

To see how it is written, let’s take an example: 10010110 (which in fact is 150 in decimal).

Every digit represents a power of two. The first digit from the right is multiplied by 2^0, the second is multiplied by 2^1 and so on.

Thus, this number is equals to: 1*2^7 + 0*2^6 + 0*2^5 + 1*2^4 + 0*2^3 + 1*2^2 + 1*2^1 + 0*2^0 = 128 + 16 + 4 + 2 = 150 (this also equals 1 * 10^2 + 5 * 10^1 + 0 * 10^0)

Here, we will use an 8 bit number which uses up to 8 digits. The biggest number will be 255 (11111111 in binary) and the smallest will be 0 (00000000 in binary).

To represent the number and operations (which will be ADD, SUBTRACT, MULTIPLY and DIVIDE), we will use a color code which is as follows:

- RED = 1
- BLUE = 0
- RED = ADD
- BLUE = SUBTRACT
- YELLOW = MULTIPLY
- WHITE = DIVIDE

The LEGO Color sensor will read the colors and convert them to numbers or operations after the user inputs numbers and operator as follows:

By default, the Color Sensor will read 0 and if there is no operation it will show “None” and end the program. The NXT screen will show information such as the read number (first in decimal, then in binary) and the total (first in decimal, then in binary). It will also show what it is reading. Please note that the Total can exceed 255 and can be less that 0.

This is a video showing the robot in action:

You can download the LDD file here (.7z) or here (.zip) and the RobotC source-code here. I have broken the robot into several groups within the LDD file, it should be fairly trivial to reassemble it using the pictures.

All comments are welcome and if you wish to contact me, you can send me an e-mail at duvit47@gmail.com.

Many thanks for using free time to post “Binary Calculator

DUVIT’s Blog”. Thanks once again -Mayra

This specific post, “Binary Calculator | DUVIT’s Blog” http://riteturnonly.com was fantastic. I am generating out a replicate to clearly show my personal buddies. Thanks a lot-Lola