Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

f

e
=
(
f
s
×
P
)
2

Basic Calculator

Name: Abbas Bilal Sami Hussein


Subject: Microprocessor and Microcontrollers
Class /Branch: Third Power Plant
Supervisor: D. Alaa Abdulhady Jaber

2019/2020
Calculator

An electronic calculator is typically a portable electronic device used to


perform calculations, ranging from basic arithmetic to complex mathematics.

The first solid-state electronic calculator was created in the early 1960s. Pocket-sized
devices became available in the 1970s, especially after the Intel 4004, the first
microprocessor, was developed by Intel for the Japanese calculator company
Busicom. They later became used commonly within the petroleum industry (oil and
gas).

Modern electronic calculators vary from cheap, give-away, credit-card-sized models


to sturdy desktop models with built-in printers. They became popular in the mid-
1970s as the incorporation of integrated circuits reduced their size and cost. By the
end of that decade, prices had dropped to the point where a basic calculator was
affordable to most and they became common in schools.

Computer operating systems as far back as early Unix have included interactive
calculator programs such as dc and hoc, and calculator functions are included in
almost all personal digital assistant (PDA) type devices, the exceptions being a few
dedicated address book and dictionary devices.

In addition to general purpose calculators, there are those designed for specific
markets. For example, there are scientific calculators which include trigonometric
and statistical calculations. Some calculators even have the ability to do computer
algebra. Graphing calculators can be used to graph functions defined on the real line,
or higher-dimensional Euclidean space. As of 2016, basic calculators cost little, but
scientific and graphing models tend to cost more.

In 1986, calculators still represented an estimated 41% of the world's general-purpose


hardware capacity to compute information. By 2007, this had diminished to less than
0.05%.

1
now there are a lot of type and prands for the calculator most of it are cheaper than
what it used to be also any one with basic knowledge of arduino with the help of net
can make one for that in this report i desided to make one from arduino.

Components of this prohect:

• Arduino Uno R3

• Breadbord

• Resistor

• Keypad 4*4

• Potinteometer

• LCD 16*2

these are the main parts used for our basic calculator now the B is for _ ,C is for
+,the B is for * and the A is for the rest are *for rest and #for = in keypad

2
The code for this project:

#include <LiquidCrystal.h>
#include <Keypad.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // setting the expander address, number of lcd
columns, number of lcd rows

long first = 0;
long second = 0;
double total = 0;
int posit = 0 ;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = { // define keypad equivalents


{'1','2','3','/'},
{'4','5','6','*'},
{'7','8','9','-'},
{'C','0','=','+'}
};
byte rowPins[ROWS] = {7 ,6 ,5 ,4}; // connect rows from keypad to Arduino
byte colPins[COLS] = {3, 2, 1, 0}; // connect columns from keypad to Arduino

Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS,


COLS); // class Keypad instance initialization

void setup(){
lcd.begin(16,2);
lcd.setCursor(5,0);
lcd.setCursor(3,1);
delay(1000);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Baisc Calculator");
lcd.setCursor(4,1);
lcd.print("Arduino");
delay(2000);
lcd.clear(); //clears the LCD screen and positions the cursor in the upper-left corner.

3
}
void loop()
{
customKey = customKeypad.getKey();
switch(customKey)
{
case '0' ... '9': // get first value for calculation
lcd.setCursor(0,0);
first = first * 10 + (customKey - '0');
lcd.print(first);
posit++;
break;

case '+':
first = (total != 0 ? total : first);
lcd.setCursor(posit,0);
lcd.print("+");
posit++;
second = SecondNumber(); // get second number
total = first + second;
lcd.setCursor(1,1);
lcd.print(total);
first = 0, second = 0; // reset the values
posit=0;
break;

case '-':
first = (total != 0 ? total : first);
lcd.setCursor(posit,0);
lcd.print("-");
posit++;
second = SecondNumber();
total = first - second;
lcd.setCursor(1,1);
lcd.print(total);
first = 0, second = 0;
posit=0;
break;

case '*':
first = (total != 0 ? total : first);
lcd.setCursor(posit,0);
lcd.print("*");

4
posit++;
second = SecondNumber();
total = first * second;
lcd.setCursor(1,1);
lcd.print(total);
first = 0, second = 0;
posit=0;
break;

case '/':
first = (total != 0 ? total : first);
lcd.setCursor(posit,0);
lcd.print("/");
posit++;
second = SecondNumber();
lcd.setCursor(1,1);

second == 0 ? lcd.print("Error") : total = (float)first / (float)second;

lcd.print(total);
first = 0, second = 0;
posit=0;
break;

case 'C':
total = 0;
first = 0;
second = 0;
posit = 0;
lcd.clear();
break;
}
}

long SecondNumber()
{
while( 1 )
{
customKey = customKeypad.getKey();
if(customKey >= '0' && customKey <= '9')
{
second = second * 10 + (customKey - '0');
lcd.setCursor(posit,0);

5
lcd.print(second);
}
if(customKey == 'C') {
total = 0;
first = 0;
second = 0;
posit = 0;
lcd.clear();
break;
}

if(customKey == '='){
lcd.setCursor(0,1);
lcd.print("=");

posit = total;
lcd.clear();
lcd.setCursor(0,1);
lcd.print("=");
break;
}
}
return second;}

6
The circuit:

References:

^ "The World’s Technological Capacity to Store, Communicate, and Compute


Information"Archived 2013-07-27 at the Wayback Machine, Martin Hilbert and Priscila López
(2011), Science, 332(6025), 60–65; see also "free access to the study" Archived 2016-04-14 at
the Wayback Machine

JEREMY BLUM-EXPLORING aRDUINO TOOLS AND TECHNIQUES FOR ENGINEERING

You might also like