Hi! I'm trying to program a counter, with a numbpad 4x4. The A,B,C,D are buttons for +1/-1 and lap +1/-1. As for the numeric inputs i wanted it to be a manual input to add to the count ( being # the "ok" button). I haven´t been able to store more than one digit input tho.. i will leave the code here and hopefully someone can gimme a hand!
Thanks in advance!
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
int count = 0;
int count2;
int carga = 1;
int carga2;
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};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
String sms = "No Input"; /* RETIRAR */
String inputnumbpad;
int numbpad;
if (customKey == 'A') {
sms.replace("No Input", "+1") ; /* RETIRAR */
Serial.println(sms); /* RETIRAR */
count += 1;
Serial.println((String) "Carga: " + carga + " Mortos: " + count ) ;
}
if ((customKey == 'B') && (count>0)) {
sms.replace("No Input", "-1") ; /* RETIRAR */
Serial.println(sms); /* RETIRAR */
count -= 1;
Serial.println((String) "Carga: " + carga + " Mortos: " + count ) ;
}
if (customKey == 'C') {
sms.replace("No Input", "C+1") ; /* RETIRAR */
Serial.println(sms); /* RETIRAR */
carga2 = carga;
count2 = count;
carga += 1;
count = 0;
Serial.println((String) "Carga: " + carga + " Mortos: " + count ) ;
}
if ((customKey == 'D') && (carga>1)) {
sms.replace("No Input", "C-1") ; /* RETIRAR */
Serial.println(sms); /* RETIRAR */
carga -= 1;
count = count2;
Serial.println((String) "Carga: " + carga + " Mortos: " + count ) ;
}
if (customKey == '*') {
sms.replace("No Input", "RESET") ; /* RETIRAR */
Serial.println(sms); /* RETIRAR */
carga = 1;
count = 0;
carga2 = 0;
count2= 0;
Serial.println((String) "Carga: " + carga + " Mortos: " + count) ;
}
while (customKey <= '0' && customKey >= '9' && customKey != '#') {
inputnumbpad += customKey;
Serial.print(inputnumbpad);
}
if (customKey == '#') {
sms.replace("No Input", "OK") ; /* RETIRAR */
Serial.println(sms); /* RETIRAR */
numbpad = inputnumbpad.toInt();
Serial.println(numbpad);
count = count + numbpad;
Serial.println(count);
}
}