All submissions

Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 
 

 

 

 

Code

/*Paste your code here*/

const int inputA = 2;
const int inputB = 3;

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

void setup() {
  pinMode(inputA, INPUT_PULLUP);
  pinMode(inputB, INPUT_PULLUP);

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

void loop() {
  int A = !digitalRead(inputA);  // invert because INPUT_PULLUP
  int B = !digitalRead(inputB);

  // Logic gates
  int andGate  = A && B;
  int orGate   = A || B;
  int nandGate = !(A && B);
  int norGate  = !(A || B);

  // Drive LEDs
  digitalWrite(ledAND, andGate);
  digitalWrite(ledOR, orGate);
  digitalWrite(ledNAND, nandGate);
  digitalWrite(ledNOR, norGate);
}

 

 

 

Output

Video

https://wokwi.com/projects/442530215554496513

Add a video of the output (know more)

 

 

 

 

Submit Your Solution

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