Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 two inputs a and b both terminals connected to ground and floating with common pin connected to digital 2 and 3 using internal pullup configuration. Outputs are LEDs, each of them connected to resistor in series to ground, LEDs' anode are connected to digital 4-7

 

 

 

Code

/*Paste your code here*/
#define input_a 2
#define input_b 3
#define or_output 4
#define and_output 5
#define nor_output 6
#define nand_output 7
bool switch_a = 0;
bool switch_b = 0;

void setup()
{
  pinMode(input_a, INPUT_PULLUP);
  pinMode(input_b, INPUT_PULLUP);
  pinMode(or_output, OUTPUT);
  pinMode(and_output, OUTPUT);
  pinMode(nor_output, OUTPUT);
  pinMode(nand_output, OUTPUT);
}

void loop()
{
  switch_a = digitalRead(input_a);
  switch_b = digitalRead(input_b);
  digitalWrite(or_output, switch_a | switch_b);
  digitalWrite(and_output, switch_a & input_b);
  digitalWrite(nor_output, !(switch_a | switch_b));
  digitalWrite(nand_output, !(switch_a & switch_b));
}

 

 

 

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!