title title title title

Sheep Compass

Sheep Compass Example

If you look deep inside computing hardware, you'll see a collection of registers holding bits ready to be compared with other bits via a set of logic gates. Things get done by interpretation of opcodes that select yet more gates to arrange themselves into particular functional units. But what is hard to see is the purpose behind these arrangements. Most end up being basic functions like adding, subtracting, multiplying, dividing, and compare size or equality. Many functions just jump to another location in memory and place or replace more bits. The point is; all of this only has meaning once you know the grand scheme, because computing is an abstraction of what you want it to portray. This example is a box of switches with five LEDs on the top. Flipping the switches you find one that turns on the LEDs. Once lit, the other switches make the LEDs be either red or green in unexplainable patterns. The meaning is totally obscure. But once the purpose is revealed, it all makes perfectly good sense, well if you're a sheep. Let me explain.

So now we have a plan as can be seen on the left. If we are the lead sheep, we manage the flock to stay put if we have grass and water, but if one or both is lacking, we must move, but which direction. So right away a compass is implied. We will indicate an okay situation with a green LED and a bad situation with a red LED. Our guidelines show certain facts about some directions. We need to develop a "truth table" that captures all cases so we won't make a mistake. On the right is our truth table.

We see the compass directions on the right side of North, South, East, and West. But now we have to apply our criteria to the situation where grass and/or water is lacking. Column A and B will show whether we have grass and water or not with a logic HIGH for yes and a logic LOW for no. C will tell there are no wolves to the north when tested. D will tell us the temperature is cold in the west if that is indeed the case. And E will tell us there is a strong wind coming from the west if that is the case. That's all we need to tell us in which of four directions to go when we need to. As we fill in the true table it becomes more clear.

All the cases where we have a problem are shown in pink. The top row is the condition where we stay put and these other conditions don't apply. Notice in the bottom right area we will default to going west if no other conditions exist. As we find out more information from the conditions a HIGH shows up in that column for any of the grass/water lacking combinations. So if there are no wolves to the north, we will go that way. If the temperature in cold in the west, our preferred direction, then we should go south where it is warmer. Better yet, if the wind is out of the west, maybe it's better to go east.

For better or worst, this is our plan and we have a truth table to guide us in wiring up the logic that will capture this abstraction. Check out the logic on the left. If we have grass and water the AND gate produces a HIGH, but the little circle symbol inverts that to a LOW. This signal will inhibit all the gates below from activating, because all inputs to an AND gate must be HIGH before the output changes. Notice the "stay put" LED is green, because the grass/water output is re-inverted to make the stay put condition valid. Also note, that if either grass, water or both switches to LOW the lower gates are now enabled to be active and the "stay put" LED should be switched to red.

Now if "No Wolves" comes on, the go north signal is issued and should turn the north LED from red to green. Also, note that only one direction LED will be green and the others have to be red. If No Wolves is off and "Cold" comes on, then south is enabled and the others are off. Likewise, when all are off except "West Wind" then we go east. Now that you know what the Sheep Compass does, the switches can be labelled and the circuit created.

This is probably not the cleanest schematic you've seen, but it worked. Sorry about the size. The images are tiny to please the iPhone people with their tiny little screens. Give me a JumboTron any day. The only thing new here is I had to add 74HC14 inverter buffers into the design to get the RGB LEDs to go from green to red with just one signal. Notice the judicious use of pull-up resistors to establish the needed HIGHs and LOWs. The four input AND gates are from 74HC20 ICs. The normal 2-input AND gates are the 74HC08 IC. The X is where I made a mistake and had to move that particular inverter back to make the logic work out correctly.

(Screw the tiny screen people - they'll just have to scroll!) On the left is a layout I drew to keep track of where all the solder joints had to be. Use 1/4 inch engineering paper to make this job a lot easier. I also made copies of the master to mark up as I went along. The lesson learned here is to reverse the layout so it's seen as if you were looking up from the bottom. Otherwise, like I had to do here, you will have to count pins on the ICs as a mirror image with the board on the solder side, which I did, and had to repair about five errors by the time I got through.

If you look closely, you will see I added a 7805 regulator to get +5 volts for the ICs. I added a 9V battery and a power switch to drive the 7805 so the box would be autonomous and not have to be plugged in via a wall-wart. It made the box even more mysterious. I didn't need to draw in the battery and its switch, because they were part of the box layout and were simple to install. I did have a devil of a time to get all the switch wires soldered and stuffed into the small box and crossed my figures nothing would pull loose or short out. It all went in fine, but I don't dare open it until the battery runs out. The video segment will show the box in operation so you can get the feel of what it's like to use the Sheep Compass. Oh, if you're wondering, I just left the blue LED leads soldered in, but not going anywhere, so there is a possibility of a further mod if I can think of a reason for the lead sheep to have another mode - more abstraction. One other thing I would do if doing this project over and that is the 220 ohms resistors were selected to optimize the current through an LED for max brightness. This is not only unnecessary, but power wasteful. You could use 680 ohms and still see the LEDs fine and make the battery last a lot longer. You typically look into the LEDs directly, so brightness here is not necessarily a good thing.

Click here for the video.