nolimitcircuit
Published © GPL3+

Arduinolator - An Arduino calculator

A working calculator!

BeginnerFull instructions provided416
Arduinolator - An Arduino calculator

Things used in this project

Hardware components

LCD (Liquid Crystal Display
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Arduino Mega 2560 R3 or Arduino Uno (both work great)
×1
Membrane Keypad
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 330 ohm
Resistor 330 ohm
×1
LED (generic)
LED (generic)
×1
Rotary potentiometer (3 legs) 10k
×1
USB that plugs to pc and arduino
×1
9V battery (generic)
9V battery (generic)
×1

Story

Read more

Schematics

Schematics

Schematics were created by me, using power point. But I uploaded an image for anyone wanting to do it, who didn't have power point.

Code

Arduinolator Project Code

C/C++
Just get a fresh new Arduino Code page, and delete everything. Then, paste this in.
#include <Keypad.h>
#include   <LiquidCrystal.h>

LiquidCrystal lcd(0, 1, 2, 3, 4, 5);
const byte ROWS = 4;
const byte COLS = 4;

char keys [ROWS] [COLS] = {
  {'1', '2', '3', '+'},
  {'4', '5', '6', '-'},
  {'7', '8', '9', '*'},
  {'C', '0', '=', '/'}
};
byte rowPins[ROWS] = {13,12,11,10};
byte colPins[COLS] = {9,8,7,6};

Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

boolean presentValue = false;
boolean next = false;
boolean final = false;
String num1, num2;
int answer;
char op;

void setup()
{
  lcd.begin(16,2); //LCD starts
  lcd.setCursor(0,0);
  lcd.print("An Arduino"); //All this is text. You can edit it
  lcd.setCursor(0,1);
  lcd.print("Calculator");
  delay(3000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("The");
  lcd.setCursor(0,1);
  lcd.print("Arduinolator!");
  delay(3000);
  lcd.clear(); //LCD clears, and you can begin using it. 
}

void loop(){

  char key = myKeypad.getKey();

  if (key != NO_KEY && (key=='1'||key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||key=='8'||key=='9'||key=='0'))
  {
    if (presentValue != true)
    {
      num1 = num1 + key;
      int numLength = num1.length();
      lcd.setCursor(15 - numLength, 0); //to adjust one whitespace for operator
      lcd.print(num1);
    }
    else 
    {
      num2 = num2 + key;
      int numLength = num2.length();
      lcd.setCursor(15 - numLength, 1);
      lcd.print(num2);
      final = true;
    }
  }

  else if (presentValue == false && key != NO_KEY && (key == '/' || key == '*' || key == '-' || key == '+'))
  {
    if (presentValue == false)
    {
      presentValue = true;
      op = key;
      lcd.setCursor(15,0);
      lcd.print(op);
    }
  }

  else if (final == true && key != NO_KEY && key == '='){
    if (op == '+'){
      answer = num1.toInt() + num2.toInt();
    }
    else if (op == '-'){
      answer = num1.toInt() - num2.toInt();
    }
    else if (op == '*'){
      answer = num1.toInt() * num2.toInt();
    }
    else if (op == '/'){
      answer = num1.toInt() / num2.toInt();
    }    
      lcd.clear();
      lcd.setCursor(15,0);
      lcd.autoscroll();
      lcd.print(answer);
      lcd.noAutoscroll();
  }
  else if (key != NO_KEY && key == 'C'){
    lcd.clear();
    presentValue = false;
    final = false;
    num1 = "";
    num2 = "";
    answer = 0;
    op = ' ';
  }
}

Credits

nolimitcircuit

nolimitcircuit

0 projects • 0 followers

Comments