void setup() {
// init serial interface
// make sure to set up the serial monitor with the same baud rate
Serial.begin(115200);
// wait 500 ms before program execution
// to account for serial interface initialization
delay(500);
// print empty line so the console output looks prettier
Serial.println("");
// number of rows in our truth table
const int N = 8;
// init inputs
bool a[N] = {0, 0, 0, 0, 1, 1, 1, 1};
bool b[N] = {0, 0, 1, 1, 0, 0, 1, 1};
bool c[N] = {0, 1, 0, 1, 0, 1, 0, 1};
// allocate memory to store output values
bool d[N];
// compute truth table
for (int i=0; i<N; i++) {
// here, we use an xor relation to simulate an xor gate
// but we can also use "and", "or" or "not"
d[i] = (not a[i] or b[i] or c[i]) and not((a[i] and b[i]) or (not b[i] and not c[i]));
}
// print truth table to serial interface
Serial.println("----------");
Serial.println("|a|b|c||d|");
Serial.println("----------");
for (int i=0; i<N; i++) {
// we use the '+' operator to concatenate strings
String line = "|" + String(a[i]) + "|" + String(b[i]) + "|" + String(c[i]) + "|" + String(d[i]) + "||";
Serial.println(line);
}
Serial.println("----------");
}
void loop() {
// nothing to do anymore... (not a[i] or b[i] or c[i]) and (a[i] or b[i] or
}