/*
See https://blog.jochumzen.com/p/entries.html Entry 7
Demonstration of a NOR latch (SR latch) built from two NOR gates.
Click S once to get the emulation started.
Click S (or keyboard 2) to "set" the latch. Q becomes 1 (left LED turns on).
Click R (or keyboard 1) to "reset" the latch. Q becomes 0.
Click Print when S, R (or neither) is pressed to investigate the NorGates
Among the chips is also the NorLatch, consisting of the two NOR gates.
S and R are also connected to the NorLatch and its output is connected to the second LED.
Observe how they have exactly the same functionality (after an initial "S" to get the Nor gates initialized).
Click Print when S, R (or neither) is pressed to investigate the NorLatch
*/
//Library with basic gates
#include <ACELBG.h>
//Create an Arduino board 2
auto* ard = new ArduinoBoard();
//Define chips
auto* ngate1 = new NorGate((char*)("Upper NOR gate"));
auto* ngate2 = new NorGate((char*)("Lower NOR gate"));
auto* norLatch = new NorLatch((char*)("Complete NOR latch"));
//Add all chips to be emulated here
Chip* chips[] = {
ngate1, ngate2, norLatch
};
//Add all connections here
ConnectionBase* connections[] = {
//Nor latch, built from Nor gates:
//Reset
new Connection(ard, 2, ngate1->X1),
//Set
new Connection(ard, 3, ngate2->X2),
//Cross
new Connection(ngate1->Y, ngate2->X1),
new Connection(ngate2->Y, ngate1->X2),
//Q
new Connection(ngate1->Y, ard, 4),
//Complete NOR latch:
new Connection(ard, 2, norLatch->Reset),
new Connection(ard, 3, norLatch->Set),
new Connection(norLatch->Q, ard, 5),
};
//Section 6: Setting up the emulation. No need to change
Emulation emulation = Emulation(ard, chips, sizeof(chips)/2,
connections, sizeof(connections)/2);
void setup() {
Serial.begin(9600); Serial.println(); Serial.println("START");
Serial.println();
emulation.makePrintPin(13, 1);
}
void loop() {
emulation.emulate();
}
R
S
Q
Print
Q NorLatch