Logic Circuit
This library let's you build a logic circuit using predefined gates and run a simulation to check the resulting logic outputs.
Basic usage
It's best to explain using an example. Take a look at this sample logic circuit that we are going to implement. It's a NAND gate implemented using NOR gates.
First let's create an empty circuit itself.
var Circuit = circuit = ;
Now, let's add some logic gates to it. All elements must be registered with the circuit object.
var nor1 = //left top nor2 = //left bottom nor3 = //middle nor4 = ; //right circuit ;
Let's register and name the input pins of the circuit. There will be two of them. I stick to the naming convention from the image. These are the "pins" which logic values can be freely changed, all other logic states are implied based on them.
circuit;
Now we must wire up the entire setup. The order in which you do this is arbitrary. In this case it's more legible to start from the output. Note the use of the circuit inputs A
and B
.
nor4 ; nor3 ; nor2 ; nor1 ;
Ok everything is pretty much ready. Just one last thing, we need to set the reference states of the inputs A
and B
circuit ;
To check the results run solve
first and then use probe
to check output values at any point of the circuit.
circuit;var result = circuit;
Examples
Check the examples
folder for more.