All submissions

Logic Gate Implementation

Solving Approach

How do you plan to solve it?

 
 

 

 

 

Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd (0x27, 16, 2);

const int switchA = 2;
const int switchB = 3;

const int IN_OR = 8;
const int IN_AND = 9;
const int IN_NOR = 10;
const int IN_NAND = 11;
int A, B;

void setup() {
  // put your setup code here, to run once:
pinMode(switchB, INPUT_PULLUP);
pinMode(switchA, INPUT_PULLUP);

pinMode(IN_OR, OUTPUT);
pinMode(IN_AND, OUTPUT);
pinMode(IN_NOR, OUTPUT);
pinMode(IN_NAND, OUTPUT);

lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("LOGIC GATES!");
delay(1500);
}

void loop() {
  // put your main code here, to run repeatedly:
 A = digitalRead(switchA);
 B = digitalRead(switchB);

int OR_OUT = A || B;
int AND_OUT = A && B;
int NOR_OUT = !(A || B);
int NAND_OUT = !(A && B);

digitalWrite(IN_OR, OR_OUT);
digitalWrite(IN_AND, AND_OUT);
digitalWrite(IN_NOR, NOR_OUT);
digitalWrite(IN_NAND, NAND_OUT);

lcd.clear();
lcd.setCursor(0,0);
lcd.print("A=");
lcd.print(A);
lcd.print("B=");
lcd.print(B);

lcd.setCursor(0, 1);
  if (OR_OUT)lcd.print("OR ");
  if (AND_OUT)lcd.print("AND  ");
  if (NOR_OUT)lcd.print("NOR ");
  if (NAND_OUT)lcd.print("NAND ");
  
  delay(200);
}



 

 

 

Output

 

 

 

Video

Add a video of the output (know more)

 

 

 

 

Submit Your Solution

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