/*
See https://blog.jochumzen.com/ entry 22
Demonstration of a full adder.
Adds A, B and Carry in (Cin)
Displays Sum and Carry out (Cout)
Example:
A = 1, B = 1, Cin = 0
Click and hold buttons 1,2 (or press 1,2 on keyboard)
1 + 1 = 10
The left-most bit is carry out, its LED is on
The right-most bit is the sum, its LED is off.
*/
//Library with basic gates
#include <ACELBC.h>
//Create an Arduino board
auto* ard = new ArduinoBoard();
//Define chips
auto* adder = new FullAdder();
//Add all chips to be emulated here
Chip* chips[] = {
adder
};
//Add all connections here
ConnectionBase* connections[] = {
new Connection(ard, 2, adder->A),
new Connection(ard, 3, adder->B),
new Connection(ard, 4, adder->Cin),
new Connection(adder->S, ard, 22),
new Connection(adder->Cout, ard, 23),
};
//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);
emulation.printOnArdEvent(1);
}
void loop() {
emulation.emulate();
}
Print
A
B
Cin
Sum
Cout