I am currently attempting to code a calculator for a bowling score. I am using a 4x4 keypad and a LCD(20,4) with an I2C which is working. I have it set up to where I can print the score and the setup for the LCD is correct, but I am struggling to write the code for the calculator. I need to store each shot, and I have not been able to do it well. Another issue is that after I get the output correct, I need to keep it even after the next input
Here is my code:
#include <LiquidCrystal_I2C.h>
#include <Key.h>
#include <Keypad.h>
const byte rows = 4;
const byte cols = 4;
char hexaKeys[rows][cols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'X','-','/','D'}
};
byte rowPins[rows] = {9, 8, 7, 6};
byte colPins[cols] = {5, 4, 3, 2};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, rows, cols );
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
Serial.begin(9600);
lcd.backlight();
lcd.init();
lcd.begin(20,4);
lcd.setCursor(1,0); //all setup for lcd frames working correctly, framework doesn't need to be touched
lcd.print("1");
lcd.setCursor(5,0);
lcd.print("2");
lcd.setCursor(9,0);
lcd.print("3");
lcd.setCursor(13,0);
lcd.print("4");
lcd.setCursor(17,0);
lcd.print("5");
lcd.setCursor(1,2);
lcd.print("6");
lcd.setCursor(5,2);
lcd.print("7");
lcd.setCursor(9,2);
lcd.print("8");
lcd.setCursor(13,2);
lcd.print("9");
lcd.setCursor(17,2);
lcd.print("1");
lcd.setCursor(18,2);
lcd.print("0");
}
void loop() {
char customKey = customKeypad.getKey();
char waitForKey();
char a;
int x = 1;
for (int i = 0; i < 12; i ++) {
if (customKey) {
Serial.println(customKey);
char a = customKey;
lcd.setCursor(1,1);
lcd.print(a);
Serial.println(a);
if ( (a <= 9) && (customKey) ) {
Serial.println(customKey);
char b = customKey;
lcd.setCursor(2,1);
lcd.println(b);
Serial.println(b);
}
}
if (customKey) {
Serial.println(customKey);
lcd.setCursor(5,1);
lcd.println(customKey);
}
}
}
If anyone could help I would greatly appreciate the help, I am semi-new to coding and have not been able to find anything online.