-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculadora.ino
98 lines (90 loc) · 2.57 KB
/
calculadora.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <LiquidCrystal.h>
#include <Keypad.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] = {A0,A1,11,10};
byte colPins[COLS] = {9,8,7,6};
Keypad Teclado = 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.setCursor(0,0);
lcd.print(" Circuitos ");
lcd.setCursor(0,1);
lcd.print(" Calculadora ");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Hecho Por ");
lcd.setCursor(0,1);
lcd.print(" Carlos Osuna ");
delay(3000);
lcd.clear();
}
void loop(){
char key = Teclado.getKey();
if (key){
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);
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 = ' ';
}
}
}