// Define pins for LEDs
const int trueLED = 8; // Green LED for TRUE (T)
const int falseLED = 9; // Red LED for FALSE (F)
// Define pins for tactical buttons (inputs)
const int trueButton1 = 2; // Tactical button for T
const int trueButton2 = 3; // Second tactical button for T
const int falseButton1 = 4; // Tactical button for F
const int falseButton2 = 5; // Second tactical button for F
// Define pins for mode switches
const int negationSwitch = 6; // Negation switch
const int conjunctionSwitch = 7; // Conjunction switch (AND)
const int disjunctionSwitch = 10; // Disjunction switch (OR)
void setup() {
// Set LED pins as output
pinMode(trueLED, OUTPUT);
pinMode(falseLED, OUTPUT);
// Set tactical button pins as input
pinMode(trueButton1, INPUT_PULLUP);
pinMode(trueButton2, INPUT_PULLUP);
pinMode(falseButton1, INPUT_PULLUP);
pinMode(falseButton2, INPUT_PULLUP);
// Set mode switch pins as input
pinMode(negationSwitch, INPUT_PULLUP);
pinMode(conjunctionSwitch, INPUT_PULLUP);
pinMode(disjunctionSwitch, INPUT_PULLUP);
}
void loop() {
// Read the state of the tactical buttons
bool trueInput = !digitalRead(trueButton1) || !digitalRead(trueButton2); // TRUE if any tactical button for T is pressed
bool falseInput = !digitalRead(falseButton1) || !digitalRead(falseButton2); // TRUE if any tactical button for F is pressed
// Read the state of the mode switches
bool negation = !digitalRead(negationSwitch);
bool conjunction = !digitalRead(conjunctionSwitch);
bool disjunction = !digitalRead(disjunctionSwitch);
// Initialize result
bool result = false;
// Check if any buttons are pressed first, if no buttons pressed, turn off LEDs
if (!trueInput && !falseInput) {
// Turn both LEDs off if no buttons are pressed
digitalWrite(trueLED, LOW);
digitalWrite(falseLED, LOW);
} else {
// Apply logical operation based on the selected mode
if (negation) {
// Negation: output is the inverse of the T input
result = !trueInput;
} else if (conjunction) {
// Conjunction (AND): output is true only if both T inputs are true and no F inputs are true
result = trueInput && !falseInput;
} else if (disjunction) {
// Disjunction (OR): output is true if at least one T input is true and no F inputs are true
result = trueInput || !falseInput;
}
// Set LEDs based on result
if (result) {
digitalWrite(trueLED, HIGH); // TRUE LED ON (T)
digitalWrite(falseLED, LOW); // FALSE LED OFF
} else {
digitalWrite(trueLED, LOW); // TRUE LED OFF
digitalWrite(falseLED, HIGH); // FALSE LED ON (F)
}
}
}