Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 
 

 

 

 

Code

/*Paste your code here*/
const int OR_LED   = 3;  // OR gate output
const int AND_LED  = 4;  // AND gate output
const int NOR_LED  = 5;  // NOR gate output
const int NAND_LED = 6;  // NAND gate output

const int BUTTON1 = 1;
const int BUTTON2 = 2;

void setup() {
  pinMode(OR_LED, OUTPUT);
  pinMode(AND_LED, OUTPUT);
  pinMode(NOR_LED, OUTPUT);
  pinMode(NAND_LED, OUTPUT);

  pinMode(BUTTON1, INPUT_PULLUP);
  pinMode(BUTTON2, INPUT_PULLUP);
}

void loop() {
  // raw buttons are ACTIVE-LOW → invert them
  int A = !digitalRead(BUTTON1);  // pressed = 1
  int B = !digitalRead(BUTTON2);  // pressed = 1

  // Logic gate outputs
  int OR_out   = A || B;
  int AND_out  = A && B;
  int NOR_out  = !(A || B);
  int NAND_out = !(A && B);

  // Output to LEDs
  digitalWrite(OR_LED,   OR_out);
  digitalWrite(AND_LED,  AND_out);
  digitalWrite(NOR_LED,  NOR_out);
  digitalWrite(NAND_LED, NAND_out);
}


 

 

 

Output

Video

Add a video of the output (know more)

 

 

 

 

Upvote
Downvote

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!