Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 Assigning logic gate funtion for respective ouput pins based on two input pins. Here, a two  way sliding switch is used whose common is connected to GPIO pin and remaining pins are connected to GND and VCC respectively. input pin is initiallised as INPUT. 
 

 

 

 

Code

/*Paste your code here*/

int A = 2;
int B = 3;

int AND = 11;
int OR = 10;
int NAND = 9;
int NOR = 8;

void setup(){
  pinMode(A, INPUT);
  pinMode(B, INPUT);
  
  pinMode(AND, OUTPUT);
  pinMode(OR, OUTPUT);
  pinMode(NAND, OUTPUT);
  pinMode(NOR, OUTPUT);
}

void loop(){
  bool a = digitalRead(A);
  bool b = digitalRead(B);
  
  digitalWrite(AND, a&b);
  digitalWrite(OR, a|b);
  digitalWrite(NAND, !(a&b));
  digitalWrite(NOR, !(a|b));
  delay(50);
}

 

 

 

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!