We're currently making a 4x3 calculator using Arduino and LCD. We're lacking buttons so instead of one button per operation, there's only one button for all operations. So far, it only does addition. How do you do the thing wherein if I pressed the OPERATION button once, it does addition, if twice, subtraction, etc.?????
we've tried many codes but failed
you could use double mapping.
If you press 2 buttons (OPERATION + 1) ==> addition
(OPERTATION + 2 ==> multiply
or you could rolling menu
first press = +
second press = -
etc
ahmed2105:
could you please explain to me by code
no time to write your code, sorry
Man dreams, and he dreams even beyond horizon! With 3x3 Keypad having no dedicated controller, expert can say very well, is it possible to implement functions as you are asking? In the good old days, we had been building sophisticated keyboard/keypad of any functionality using 8279 Keyboard Controller!
Anyway, I have given below a program (that you have already done it!) that takes two numbers from a 4x4 keypad, add them together (in response of * command) and show the result (also the input as ASCII) on an I2C LCD.
/#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte myData[4];
int i=0;
bool flag = true;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
}
void loop()
{
char customKey = customKeypad.getKey();
if (flag == true)
{
if (customKey)
{
myData[i] = (customKey); //goes ASCII code in array
lcd.print(myData[i], HEX);//(customKey);
i++;
}
if(i == 4)
{
flag = false;
i=0;
}
}
if(customKey == '*')
{
myData[0] = (myData[0] << 4) | (myData[1] & 0x0F);
myData[2] = (myData[2] << 4) | (myData[3] & 0x0F);
byte x = myData[0] + myData[2]; //46 = 0100 0110
byte x1 = x;
lcd.setCursor(0, 1);
lcd.write((x1>>4) + 0x30);
lcd.write( (x & 0x0F) + 0x30);
}
}