All submissions

Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 
 

 

 

 

Code

/*Paste your code here*/

const int button1 = 13;    
const int button2 = 12;    
const int ledpin1  = 5;
const int ledpin2  = 4;
const int ledpin3  = 3;
const int ledpin4  = 2;

void setup() {
  // put your setup code here, to run once:
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(ledpin1, OUTPUT);
pinMode(ledpin2, OUTPUT);
pinMode(ledpin3, OUTPUT);
pinMode(ledpin4, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

bool b1 = digitalRead(button1) == LOW;
bool b2 = digitalRead(button2) == LOW;

if (b1 || b2) {
  digitalWrite(5, HIGH);
} else {
  digitalWrite(5, LOW);
}

if ( b1 && b2) {
  digitalWrite(4, HIGH);
} else {
  digitalWrite(4, LOW);
}

 if (!(b1 || b2)) {
    digitalWrite(ledpin3, HIGH);
  } else {
    digitalWrite(ledpin3, LOW);
  }

  if (!(b1 && b2)) {
    digitalWrite(ledpin4, HIGH);
  } else {
    digitalWrite(ledpin4, LOW);
  }
}

Output

Video

 

 

 

 

Submit Your Solution

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