All submissions

Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 
 

 

 

 

Code

const int sw1 = 2;
const int sw2 = 3;

const int ledAND = 8;
const int ledOR  = 9;
const int ledNAND = 10;
const int ledNOR  = 11;

void setup() {
  pinMode(sw1, INPUT_PULLUP);
  pinMode(sw2, INPUT_PULLUP);

  pinMode(ledAND, OUTPUT);
  pinMode(ledOR, OUTPUT);
  pinMode(ledNAND, OUTPUT);
  pinMode(ledNOR, OUTPUT);
}

void loop() {
  // Invert logic because INPUT_PULLUP: LOW = pressed
  bool A = !digitalRead(sw1);
  bool B = !digitalRead(sw2);

  // Logic gate outputs
  digitalWrite(ledAND, A && B);
  digitalWrite(ledOR, A || B);
  digitalWrite(ledNAND, !(A && B));
  digitalWrite(ledNOR, !(A || B));
}



 

 

 

Output

Video

Add a video of the output (know more)

 

 

 

 

Submit Your Solution

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