Now that you have hopefully verified that your system is working physically, it might be nice to take a look at how the code works. The following gists (send code
and receive code
) and the accompanying pictures show what the code is, although you should already have it downloaded if you have tested your system. We will provide a short explanation of what is happening with each.
The Sender code does a few different things. First it establishes some variables, the most important of which are the instructions for the sending device, labeled 'a' through 'f' and are character arrays. These arrays function much like CPU instructions for something like a Hack CPU, although it is very much simplified; the first several of the numbers in these instructions are needed for determining the specification of IR signal to send and are not essential to understanding the system itself. The most important of the the 'bits' of the instruction are the last three, which determine which LED is turned on (or off). These are the workhorses of our very small instruction set, and it is important to note that more significant information could be sent and acted upon. We imagine that if you built up some infrastructure, then you could send things such as pictures or objects of classes you created that could be used as input on your Receiver nodes or more complicated instruction sets that could mimic something more akin to a full computer or CPU.
The fourth 'bit' from the right could be implemented as a control 'bit' if you wanted to add more nodes to your system. You could change this to various numbers that would represent which device (or group of devices) the instruction was intended for and then the Receiver devices would check to see if the instruction was for them, and execute it if so, and ignore the instruction if not.
The Receiver code essentially turns on the infrared receiver and then listens for input. Once some sort of IR input has been received, it then takes this data, which is a string of characters in this example, and executes an instruction (turning on or off an LED) depending on the instruction that was sent. In this system, the last three 'bits' represent which LED to turn on and which to turn off. If the bit is 1, then the corresponding LED is turned on, and of it is 0, then that LED is turned off. If you were to add more nodes to your system, it would be necessary to code each device to determine if the instruction it received was actually for it, which could be implemented by checking for a control 'bit' before executing the instruction.
What we have provided is more of a template than a complete system, and it is provided as a system to be built upon. Feel free to try out your own programs and test the capabilities of the platform. Our original intentions were to build a distributed Harvard Architecture, which is a computing platform that physically separates data memory and instructions memory. We wanted to do this by separating each of the operations associated with both data types into its own Arduino, with both devices communicating via infrared light. There are surely plenty of cool things that could be made with this setup, however, and we hope you have fun testing out new configurations or programs. If you do come up with something cool, please share it back with us, we would like to see it.