Hi, I'm making an ATM in which we have to enter our **BMI(Body Mass Index)**and I am having some difficulties in working with keypad see I have programmed the Arduino in the way that I can Enter my BMI and I will be give money as BMI * 10 but I want to add backspace when I click the # Key. So can anyone help me with this problem This is My Code
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A0, A1, A2, A3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
float enteredBMI = 0.0; // Variable to store entered BMI
float totalMoney = 0.0; // Variable to store total money
void setup() {
Serial.begin(9600);
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key == 'A') {
// The user pressed "A," calculate total money and display it
totalMoney = enteredBMI * 10.0;
Serial.print("Total Money: $");
Serial.println(totalMoney);
enteredBMI = 0.0; // Clear the entered BMI
} else {
Serial.print(key); // Print the entered key
enteredBMI = enteredBMI * 10.0 + (key - '0'); // Append key to enteredBMI
}
}
}