Skip to content

Instantly share code, notes, and snippets.

@p1nesap
Created January 19, 2017 20:23
Show Gist options
  • Save p1nesap/cb43f010849d475362337206603b8c50 to your computer and use it in GitHub Desktop.
Save p1nesap/cb43f010849d475362337206603b8c50 to your computer and use it in GitHub Desktop.
i2c Arduino display output from 4093 IC half-adder NAND
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
int carry = 2;
int sum = 5;
int carval = 0;
int sumval = 0;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
void setup()
{
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
pinMode(carry, INPUT);
pinMode(sum, INPUT);
}
void loop()
{
sumval = digitalRead(sum);
carval = digitalRead(carry);
lcd.setCursor(0, 0);
if ((sumval == 0) && (carval == 0))
{
lcd.print("Sum & carry = 0");
lcd.setCursor(0, 1);
lcd.print("Switches off.");
}
if ((sumval == 1) && (carval == 0))
{
lcd.print("1 + 0 = Sum 1");
lcd.setCursor(0, 1);
lcd.print("One switch on.");
}
else if ((sumval == 0) && (carval == 1))
{
lcd.print("Sum 0, Carry 1");
lcd.setCursor(0, 1);
lcd.print("Both switches on.");
}
delay(500);
lcd.clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment