Skip to content

Instantly share code, notes, and snippets.

@p1nesap
Created January 31, 2017 00:50
Show Gist options
  • Save p1nesap/31c3b912b9f96a152a7ce833015166ec to your computer and use it in GitHub Desktop.
Save p1nesap/31c3b912b9f96a152a7ce833015166ec to your computer and use it in GitHub Desktop.
//Follow Project Paul on YouTube: https://www.youtube.com/c/frugalteq
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
int carry = 10;
int sum2 = 9;
int sum1 = 8;
int sum2val = 0;
int sum1val = 0;
int carval = 0;
int pins = 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(sum1, INPUT);
pinMode(sum2, INPUT);
}
void loop()
{
sum1val = digitalRead(sum1);
sum2val = digitalRead(sum2);
carval = digitalRead(carry);
pins = PINB & 0x7; //reads port registers 8 - 13 INPUT state
lcd.setCursor(0, 0);
//SWITCH/CASE
switch (pins) {
case 0:
sum1val = 0;
sum2val = 0;
carval = 0;
lcd.print("0");
break;
case 1:
sum1val = 1;
sum2val = 0;
carval = 0;
lcd.print("1");
break;
case 2:
sum1val = 0;
sum2val = 1;
carval = 0;
lcd.print("2");
break;
case 3:
sum1val = 1;
sum2val = 1;
carval = 0;
lcd.print("3");
break;
case 4:
sum1val = 0;
sum2val = 0;
carval = 1;
lcd.print("4");
break;
case 5:
sum1val = 1;
sum2val = 0;
carval = 1;
lcd.print("5");
break;
case 6:
sum1val = 0;
sum2val = 1;
carval = 1;
lcd.print("6");
break;
}
//END SWITCH
//Can use if/else instead of switch/case
/*
if ((sum1val == 0) && (sum2val == 0) && (carval == 0))
{
lcd.print("0");
}
else if ((sum1val == 1) && (sum2val == 0) && (carval == 0))
{
lcd.print("1");
}
else if ((sum1val == 0) && (sum2val == 1) && (carval == 0))
{
lcd.print("2");
}
else if ((sum1val == 1) && (sum2val == 1) && (carval == 0))
{
lcd.print("3");
}
else if ((sum1val == 0) && (sum2val == 0) && (carval == 1))
{
lcd.print("4");
}
else if ((sum1val == 1) && (sum2val == 0) && (carval == 1))
{
lcd.print("5");
}
else if ((sum1val == 0) && (sum2val == 1) && (carval == 1))
{
lcd.print("6");
}
*/
delay(100);
lcd.clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment