/*
See https://blog.jochumzen.com/2025/03/entry-6-acel.html
Start the simulation (Green play-button)
Click on X1 and/or X2 (press 1 and/or 2 on keyboard) and observe Y.
Y is only 1 (on) when X1 and X2 are both pressed.
Stop the simulation and replace "AndGate" below with one of the following:
Inverter
OrGate
NandGate
NorGate
XorGate
XnorGate
Start the simulation. Click on X1 and/or X2 and observe Y. confirm with the truth table for respective gate
Note For Xor and Xnor, see entry 22.
*/
//Library with basic gates
#include <ACELBG.h>
//Create an Arduino board
auto* ard = new ArduinoBoard();
//Define chips
auto* gate = new AndGate();
//Add all chips to be emulated here
Chip* chips[] = {
gate
};
//Add all connections here
ConnectionBase* connections[] = {
//Connect Arduino pin 2 to the first input of gate, X1
new Connection(ard, 2, gate->X1),
//Connect Arduino pin 3 to the second input of gate, X2
new Connection(ard, 3, gate->X2),
//Connect the output of gate, named Y, to Arduino pin 4
new Connection(gate->Y, ard, 4),
};
//Section 6: Setting up the emulation. No need to change
Emulation emulation = Emulation(ard, chips, sizeof(chips)/2,
connections, sizeof(connections)/2);
void setup() {
emulation.init();
}
void loop() {
emulation.emulate();
}
X1
X2
Y