Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 I focus my attention to write four if-else sentences where I evaluate the state of each input tthen I write my output for each logic gate. For example

if INPUT1= 0 and INPUT2 = 0 ---> OR = 0, AND = 0, NOR = 1, NAND = 1 

This is going to be the skeleton of my logic and the only thing left is to traduce it into arduino code

 

Code

/*Paste your code here*/
const char ledOR = 13;
const char ledAND = 12;
const char ledNOR = 11;
const char ledNAND = 10;
const char SW1 = 7;
const char SW2 = 6;

void setup() {

for(int i = 10; i<=13; i++) pinMode(i, OUTPUT);

for(int i = 10; i<=13; i++) digitalWrite(i, LOW);

for(int i = 6; i<=7; i++) pinMode(i, INPUT_PULLUP);

}

void loop() {

unsigned char estado1 = digitalRead(SW1);
unsigned char estado2 = digitalRead(SW2);

if(estado1 == 0 && estado2 == 0){
digitalWrite(ledOR, LOW);
digitalWrite(ledAND, LOW);
digitalWrite(ledNOR, HIGH);
digitalWrite(ledNAND, HIGH);
}

else if(estado1 == 0 && estado2 == 1){
digitalWrite(ledOR, HIGH);
digitalWrite(ledAND, LOW);
digitalWrite(ledNOR, LOW);
digitalWrite(ledNAND, HIGH);
}

else if(estado1 == 1 && estado2 == 0){
digitalWrite(ledOR, HIGH);
digitalWrite(ledAND, LOW);
digitalWrite(ledNOR, LOW);
digitalWrite(ledNAND, HIGH);
}

else if(estado1 == 1 && estado2 == 1){
digitalWrite(ledOR, HIGH);
digitalWrite(ledAND, HIGH);
digitalWrite(ledNOR, LOW);
digitalWrite(ledNAND, LOW);
}

}

 

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!