Lately I’ve been reading through Code: The Hidden Language of Computer Hardware and Software. I highly recommend the book whether you’ve taken a computer organization class or not. Looking at the example diagrams in the book I started to get the feeling I’d get more out of the experience if I built them myself instead of just reading about them. Unfortunately I don’t have a Radioshack near by, and I don’t have any spare components lying around either. Besides that, it’s tough to build something like the 8-bit full adder by hand. I do own a copy of Minecraft though, which has a form of electricity transmitted through a material called redstone. What does it look like to build the examples in CODE in Minecraft?
A simple circuit
One of the first circuits from the book is just a flashlight powered by a battery (to send Morse code with). We can do something similar with redstone:
Here we’re using a redstone lamp as our light bulb and a redstone torch as a battery.
Of course we’ll want to be able to signal so we’ll need the equivalent of a switch (called a lever in Minecraft):
But in Minecraft in particular, the gate lever can serve as our battery directly
In all the simulations so far, we only need one line of redstone from the source to the sink in order to complete the circuit and power something. In reality, we would need to complete a circuit, but you can sort of think of this as both ends of the circuit having an implicit ground.
Switches or levers also can’t serve as power sources in reality (not to mention that real batteries eventually run out). Minecraft collapses this part of the circuit for convenience.
The next important circuit to cover is the relay, which allows us to boost a signal over long distances and serves as the basis for creating logic gates. What does a relay look like in Minecraft?
Minecraft also includes a built in relay called a repeater
Which is a special block that does the same thing. Unfortunately these repeaters aren’t the same real repeaters. They can’t be used as the basis for logical gates because they don’t have the same physical properties. That’s OK though because we can still build logic gates with redstone.
Here’s the simplest gate we can build, an inverter (or
The physics of redstone is slightly different than now this works with a relay, but what’s happening here is
- The signal comes from the lever, sending an ON signal through the redstone to the block
- This on signal interacts with the torch first. When a redstone torch receives an ON signal, it changes its output to OFF
- There is no ON signal going to the redstone connected to the torch anymore, so there is no power for the redstone lamp, it turns off.
If you look at the above picture for the manual repeater, you’ll see that in minecraft a repeater is really just two inverters stuck together. The first inverter gets an ON signal and changes its output to OFF, then the next inverter does the opposite.
Next lets build an OR gate
This one is fairly simple, because of the way redstone works, we don’t actually even need the repeaters. We could just wire the Redstone directly together but the current would flow in both directions which can be dangerous in more complicated circuits. Since the special minecraft repeaters are directional (they only allow current to flow in one way), we use them leading up to the gate to protect the rest of the circuit. As you can see, one input is on and the lamp still turns on. Since redstone current doesn’t cancel itself out, turning the other switch to on would keep the lamp lit. Only turning off both switches would turn off the lamp completely.
And gates are a little more complicated
Here we have two inverters, an OR gate, and finally another inverter. Lets look at the truth table for this circuit to see that it does match the expected output of an AND gate:
|A||B||not A||not B||(not A) or (not B)||not((not A) or (not B))||A and B|
If we have our gate correct, the last two columns should be equivalent, which we can see they are. You can also show this result with Demorgans Law.
Minecraft gates end up being built from different components than real logic gates because the physics of
minecraft are different than the real world. Nevertheless, once you have inverters,
you can build any logical circuit. This means we can use these gates to build both half and full adders
which we’ll see next time.