Rizwan Ahmed
Published

Arduino Based Digital Calculator

This project is based on digital calculator for converting whole number (decimal) to Binary, Hexa, and Octa decimal system

IntermediateFull instructions provided4 hours3,291
Arduino Based Digital Calculator

Things used in this project

Story

Read more

Schematics

Digital Calculator

Code

Digital Calculator

C/C++
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

LiquidCrystal_I2C lcd (0x27, 16, 2);

const byte rows = 4;
const byte cols = 4;

char hexKeys [rows][cols] = {

  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[rows] = {4, 5, 6, 7};
byte colPins[cols] = {0, 1, 2, 3};

Keypad kpd = Keypad (makeKeymap(hexKeys), rowPins, colPins, rows, cols);

long number = 0;

char dynamicKeys;
String string = "";

boolean enterkey_state;
boolean binButton_state;
boolean hexButton_state;
boolean octButton_state;
boolean decButton_state;

void setup()
{
  lcd.begin();
  lcd.backlight();

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Initializing");
  for (int i = 12; i <= 16; i++)
  {
    delay(200);
    lcd.print("*");
  }
  delay(3000);
  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("Digital");
  lcd.setCursor(0, 1);
  lcd.print("Calculator");

  delay(3000);
  lcd.clear();
}

void loop()
{
  enterkey_state = false;
  binButton_state = false;
  hexButton_state = false;
  octButton_state = false;
  decButton_state = false;
  
  dynamicKeys = kpd.getKey();

  if (dynamicKeys)
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("|>");
    string = string + dynamicKeys;
    lcd.print(string);
    number = string.toInt();
  }

  if (dynamicKeys == 'A')
  {
    octButton_state = true;
    
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("OctaDecimal");
    lcd.setCursor(0, 1);
    lcd.print("|>");
    lcd.print(number, OCT);
  }
  else if (dynamicKeys == 'B')
  {
    binButton_state = true;
    
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Binary");
    lcd.setCursor(0, 1);
    lcd.print("|>");
    lcd.print(number, BIN);
  }
  else if (dynamicKeys == 'C')
  {
    hexButton_state = true;
    
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("HexaDecimal");
    lcd.setCursor(0, 1);
    lcd.print("|>");
    lcd.print(number, HEX);
  }
  else if (dynamicKeys == 'D')
  {
    decButton_state = true;
    
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Decimal");
    lcd.setCursor(0, 1);
    lcd.print("|>");
    lcd.print(number, DEC);
  }
  else if (dynamicKeys == '#')
  {
    enterkey_state = true;
    
    lcd.clear();
    lcd.print("Entered Number");
    lcd.setCursor(0, 1);
    lcd.print("|>");
    lcd.print(number);
  }
  else if (dynamicKeys == '*')
  {
    number = 0;
    string = "";
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter Number");
    lcd.setCursor(0, 1);
    lcd.print("|>");
  }
}

Credits

Rizwan Ahmed

Rizwan Ahmed

4 projects • 1 follower
A junior IoT engineer who likes to play with the Arduino and Raspberry Pi to gain skills and knowledge

Comments