User Guide for Brown Dog Gadgets models including: Crazy Circuits Bit Board, Binary Calculator, FHUZIY9KJIKP0ME

Binary Calculator

Binary Calculator

FHUZIY9KJIKP0ME

Binary Calculator - Instructables

or 0 you can press the pushbutton to calculate the value. With all four switches in the off position, the binary ... Binary Calculator Code.


File Info : application/pdf, 3 Pages, 1.08MB

PDF preview unavailable. Download the PDF instead.

Binary Calculator
Binary Calculator
* What You Need: 1 x Crazy Circuits Bit Board 1 x micro:bit 1 x 7 Segment Display 4 x Jumper Wires 4 x Slide Switch 1 x Jumbo Pushbutton 1 x LEGO Baseplate Misc. LEGO Pieces 1/8" Maker Tape

00:005

*1 How it Works: There are four switches that can be set to an on or off postion. The on position is equal to 1, and the off position is equal to 0.

After setting each switch into a position to equal 1 or 0 you can press the pushbutton to calculate the value.

With all four switches in the off position, the binary number 0000 would translate to 0 in decimal.

When a switch is in the on position you add the value for that switch (8, 4, 2, or 1) to the total which will be shown when you press the CALCULATE button.
If the switches are off, on, off, on while reading left to right your binary number would be 0101 and would add 0 + 4 + 0 + 1 for a total of 5.

OFF=0 ON=1

Each time you press the CALCUATE button it resets the number to zero, and then adds up the results of the switches and shows it on the 4 digit display connected to the Bit Board.

8

4

0 19 GND

9 3.3v 20

CLK -> Pin 13 DIO -> Pin 14 VCC -> Pin + (Positive) GND -> Pin - (Negative)

13

12 1

11

10

0

15 14

13

+-

-

+

4

3

2

1

2

1

For more fun projects and educational guides visit us at BrownDogGadgets.com

5

+

14

-

6

15

3.3v 8
7

16

16

GND

CALCULATE

Binary Numbering System
*1 To the right is a chart showing how you would translate a binary number into a decimal number.
You can get any value between 0 and 15 with just four binary digits. (This is a 4 bit register.)
1, 2, 4, and 8 are the only numbers we need to accomplish our counting. If we need 3 we just add 1 and 2. If we need 7 we add 4 and 2 and 1, and so on up to 15.
If this is a 4 bit register, what would an 8 bit register look like? To start with, you would have 8 digits instead of 4 and you would be able to count much higher of course.
Here is our 8 bit register. It has 8 "slots" that we can toggle on/off to create our decimal number. (And yes, each "slot" holds one bit which is why this is referred to as 8 bit.)
128 64 32 16 8 4 2 1 0 0 0 0 0 0 0 0
If you examine the numbers from right to left you'll notice that the next digit is always one more than the total we can get using the previous numbers combined.
For instance, 1 + 2 = 3, so we don't need a 3 but we do need a 4 because we can't count to 4 just using 1 and 2. Likewise, 4 + 2 + 1 = 7, so the next value we need is 8. This continutes on along the string of numbers. 64 + 32 + 16 + 8 + 4 + 2 + 1 = 127. If we add 127 and 128 we get 255. Now, if you're familiar with 8 bit and know that it's related to the number 256, that's because we need to count zero! (A count from 0 to 255 gives us 256 values because when computers count they count 0 as a valid value.)
These bits are part of a base 2 numbers system. While base 10 numbers look like 10, 100, 1,000, 10,000, etc. Our base 2 numbers look like 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, etc.
With our 4 bits, that means 2 to the power of 4 (or 2 x 2 x 2 x 2) which equals 16, and the highest value we can count to with our 8 bit register. (Remember, we're including zero, so 0 to 15 is really 16 values.)
The term `bit' is short for `binary digit'
For more fun projects and educational guides visit us at BrownDogGadgets.com

Binary

Decimal

8421

0000 0

0001 1

0010 2

0011 3

0100 4

0101 5

0110 6

0111 7

1000 8

1001 9

1010 10

1011 11

1100 12

1101 13

1110 14

1111 15

4 bit register

Binary Calculator Code

Disable the built-in LED matrix
For each of the pins we connect to for the four switches and the pushbutton we need to set them as "up" pins so that when we turn "on" the switch, or push the button, the are pulled "down" to ground by completing the connection

We have a variable called theNumber which will hold the value we get when we add our
registers together
We have a variable called tm which represents the 7 Segment Display we are
using to display the decimal number
We have the 7 Segment Display connected to Pin 13 and Pin 14, so we specify that here

*1 Lfewohtr'eastphctapeakenBenisnianeagelro!ywoCkhaaaltct uitshlaetocrosdoe

The start section of the code runs just once when our program begins (typically this is when the micro:bit is powered on) so it contains a lot of setup statements.
The forever section runs in a loop for as long as the micro:bit is turned on and receiving power.

In other systems the start section is referred to as the setup and the forever is referred to as the loop. They may have different names, but they serve the same purpose.
https://makecode.microbit.org/_avbceA0oHcob

For more fun projects and educational guides visit us at BrownDogGadgets.com

Our pushbutton is connected to Pin 4, so we don't do anything until the button is pressed We set our theNumber variable to 0 each time the button is pressed
We have four if/then statements to evaluate each of the four switches
In each case, if the switch is in the on position (and it is pulled down and equals 0) we then add to theNumber to increase the value
From left to right the first switch represents 8, the second 4, the third 2, and the fourth 1
For each if/them statement if the switch is in the off position then the else part of the if/then statement is triggered and the value is increased by 0 (which means it does not increase in value)
We constantly display the value for theNumber on the 7 Segment Display, which only changes when we press the button



References

Adobe PDF library 15.00 Adobe Illustrator(R) 24.0