#include <LiquidCrystal.h>
#include <Keypad.h>
/* Display */
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int buttons[] = {6, A4, A5};
/* Keypad setup */
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 4;
byte rowPins[KEYPAD_ROWS] = {5, 4, 3, 2};
byte colPins[KEYPAD_COLS] = {A3, A2, A1, A0};
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'.', '0', '=', '/'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
String numberInput = ""; // Store the entered number as a string
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.cursor();
lcd.setCursor(0, 0);
for (int i = 0; i <= 2; i++) {
pinMode(buttons[i], INPUT);
}
}
void processInput(char key) {
if (key == '>') {
// When '>' is entered, convert the inputted number to an integer and display the result
int enteredNumber = numberInput.toInt();
int result;
if (digitalRead(buttons[0]) == HIGH) {
result = enteredNumber * 2;
} else if (digitalRead(buttons[1]) == HIGH) {
result = enteredNumber * 3;
} else if (digitalRead(buttons[2]) == HIGH) {
result = enteredNumber * 4;
}
lcd.clear();
lcd.print("Result: ");
lcd.print(result);
numberInput = ""; // Clear the input for the next iteration
delay(2000);
lcd.clear();
} else {
lcd.print(key);
numberInput += key; // Concatenate the entered digits to the numberInput string
}
}
void loop() {
char key = keypad.getKey();
if (key) {
processInput(key);
}
}