Big thanks to DRV47 for posting this!
Have you ever sat and wondered, “Man.. I would love to be able to have a robot that could read a string of lego bricks that I put in a row and tell me the binary representation for it… and maybe even add or subtrack the numbers. Hmm…”
WELL YOU’RE IN LUCK!
DRV47 has built this robot for you. The robot uses an NXT and is built using a single NXT 2.0 kit that you can get off the shelf from local stores nowadays.
They programmed in, of course, ROBOTC.
Take a look at the photos below:
How it works
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 DRV47, you can send him an e-mail at email@example.com.