How do you plan to solve it?
/*Paste your code here*/
#define SW1 2
#define SW2 3
#define LED_AND 8
#define LED_OR 9
#define LED_NAND 10
#define LED_NOR 11
void setup() {
pinMode(SW1, INPUT_PULLUP); // Switch with pull-up
pinMode(SW2, INPUT_PULLUP);
pinMode(LED_AND, OUTPUT);
pinMode(LED_OR, OUTPUT);
pinMode(LED_NAND, OUTPUT);
pinMode(LED_NOR, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Read switches (LOW = pressed, HIGH = released)
int a = !digitalRead(SW1); // invert so pressed = 1
int b = !digitalRead(SW2);
// Logic gates
int and_out = a & b;
int or_out = a | b;
int nand_out = !(a & b);
int nor_out = !(a | b);
// Drive LEDs
digitalWrite(LED_AND, and_out);
digitalWrite(LED_OR, or_out);
digitalWrite(LED_NAND, nand_out);
digitalWrite(LED_NOR, nor_out);
// Print on serial monitor
Serial.print("A=");
Serial.print(a);
Serial.print(" B=");
Serial.print(b);
Serial.print(" | AND=");
Serial.print(and_out);
Serial.print(" OR=");
Serial.print(or_out);
Serial.print(" NAND=");
Serial.print(nand_out);
Serial.print(" NOR=");
Serial.println(nor_out);
delay(200);
}
Add a video of the output (know more)