Simple 3-Bit Color Light Computer

                    

Source Code Binary Code   Memory   CPU
  
  
0000
  
P0
Q0
 
 


Instruction Set for Simple 3-Bit Light Computer

100 Red R
010 Green G
001 Blue B
110 Yellow Y
101 Magenta M
011 Cyan C
000 Black K
111 White W


-- Description --

This simple computer uses a three bit instruction to select a color for the output "light". The first bit of each instruction controls the "red" component of the color. The second bit of each instruction controls the "green" component of the color. The third bit of each instruction controls the "blue" component of the color. These three bits can be combined to give a total of 8 colors as shown in the instruction set table above.

This computer can be programmed in either binary (1's and 0's) or with a single letter for each color ("r", "g", "b", "y", "m", "c", "k", "w"). These letters are called "Source Code", and they are entered into the "Source Code" text block. Each instruction letter of the source code may be separated from other instruction letters with optional spaces or new lines. These instruction letters are much easier to remember (and to type) than the three-bit binary instruction codes for this computer.

The "Compile Program" button will convert all of the source code into binary instructions and show the binary program (along with addresses) in the "Binary Code" text block. Pushing the "Compile" button will write over any binary instructions in the "Binary Code" text block.

Once a program is compiled (or entered directly in binary) it can be loaded from the Binary Code block into the computer Memory using the Load Program button.

Once a program is loaded into memory, it can be run with the "Run/Stop" button. The CPU shows the program counter ("P") and the state of the output light ("Q"). This computer can hold up to 256 instructions. The controls are explained here:

The normal programming process goes as follows:

  1. Write or modify the program in the "Source Code" block
  2. Compile the "Source Code" to "Binary Code" with the "Compile Program" button
  3. Load the "Binary Code" program into "Memory" with the "Load Program" button
  4. Run the program with the "Run/Stop" button or step through it with the "Step" button.

The process is iterative as each program is written and tested.


-- Sample Programs --


Caution Light:

This very simple program flashes a yellow caution light. The time that the light stays on (and off) is controlled by the speed (instructions per second).

yk


Traffic Light:

This simple program cycles through the colors of a traffic light (green, yellow, and red). The program can be run at any speed (depending on your patience). It was designed for the default speed of 2 instructions per second.

ggggggggggyyyyrrrrrrrr


Smoothly Changing Colors:

This simple program cycles through all possible colors except white. In each transition, only one of the color bits is changed. So the transition from black to red only turns on the red bit. Since yellow is both red and green, the transition from red to yellow only requires turing on the green bit. Similarly, transitioning from yellow to green is done by turning off the red bit. Green transitions to cyan by adding the blue bit, and cyan transitions to blue by turning off the green bit. Blue transitions to magenta by adding the red bit, and magenta returns to red by turning off the blue bit. Turing off the red bit then returns to black and the pattern repeats (black, red, yellow, green, cyan, blue, magenta, red, and black).
This program runs at any speed, but the slowest speed is best for observing the single bit changing patterns.

krygcbmrk


Bouncing Colors:

This simple program "bounces" between red (on left) and blue (on right) while passing through green (in the middle). The transition colors of yellow (between red and green) and cyan (between green and blue) are shown briefly during the transitions.
This program runs at any speed, but the "bouncing" effect is more noticable at higher speeds like 16 or 32 instructions per second.

rrrrrr yy gggg cc bbbbbb cc gggg yy