Need help with membrane switch module

I am trying to create a program that will use the membrane switch module to activate a fingerprint module, just started but encountered a problem I couldn’t solve.

At the moment, I am working on the part that will add a new fingerprint to the storage, but for this I need to choose a slot, the program works but when I get to the second time I need to use the membrane switch, it just wont read anything.
Anything in the program works, only the bolded section wont.
Any ideas why?

The Code:
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
bool flag = false;
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;

// include the library code:
#include <LiquidCrystal.h>
LiquidCrystal lcd( 8, 9, 10, 11, 12, 13);

#include <Keypad.h>
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] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A3, A2, A1, A0}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Keypad customKeypad2 = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
// Print a message to the LCD.
lcd.print(“What would you”);
lcd.setCursor(0, 1);
lcd.print(“like to do?”);
finger.begin(57600);
}

uint8_t readnumber(void) {
uint8_t num = 0;

while (num == 0) {
while (! Serial.available());
num = Serial.parseInt();
}
return num;
}

void loop() {
while(flag==false){
char customKey = customKeypad.getKey();
Serial.print(customKey);
if(customKey){
lcd.clear();
lcd.print(customKey);
}
if(customKey==‘1’){
addFingerPrint();
}
}
}

void addFingerPrint(){
flag=true;
Serial.begin(9600);
lcd.clear();
while (!Serial); // For Yun/Leo/Micro/Zero/…
delay(100);
lcd.print(“Add Fingerprint”);
lcd.setCursor(0,1);
lcd.print(“Program!”);
delay(700);
lcd.clear();
lcd.print(“Ready!”);
delay(200);
lcd.clear();
lcd.print(“Insert a number!”);
lcd.setCursor(0, 1);
lcd.print("(1-127)");

char kk = customKeypad2.getKey();
Serial.print(kk);
if(kk==‘5’){
lcd.clear();
lcd.print(“aaa”);
}
}

Serial.begin(9600);

That needs to be in setup, not in your addFingerPrint function. I’m not sure but I think calling it more than once causes some sort of problems.

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Keypad customKeypad2 = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

Why create 2 keypad objects that use the same pins and maps?

Delta_G:

Serial.begin(9600);

That needs to be in setup, not in your addFingerPrint function. I’m not sure but I think calling it more than once causes some sort of problems.

Tried removing it from the function, did no change except of making me have to remove the the Serial.print lol.

It didn’t make you have to remove the serial print. What are you talking about? If you have a begin in setup then you can use serial anywhere in your sketch.

Delta_G:
It didn’t make you have to remove the serial print. What are you talking about? If you have a begin in setup then you can use serial anywhere in your sketch.

You are right, it showed me a compiling error but now I see it has nothing to do with the Serial, my bad.
But still the keypad wont return any new chars there.

Which brings us back to the question in reply #2 that you haven’t answered.

Delta_G:
Which brings us back to the question in reply #2 that you haven’t answered.

I tried using both the same one and a new one, because my last test was with a new keypad so I uploaded it like this, but the same problem occurred while using the same one and while using a new one.

Still, why have two identical objects in your code. That may have something to do with your problem. I don’t know enough about that keypad library to be sure. But it’s definitely not right and should be fixed.

Delta_G:
Still, why have two identical objects in your code. That may have something to do with your problem. I don’t know enough about that keypad library to be sure. But it’s definitely not right and should be fixed.

As I said, I tried both ways, with no 2 identical objects either, always the same problem, its just wont work.

adizadik:
As I said, I tried both ways, with no 2 identical objects either, always the same problem, its just wont work.

Ok. Well if you don’t want to show us that then there’s not a lot we can do. Best of luck to you. When you realize that we can’t debug what we can’t see then maybe you’ll clue in on what you need to do.

That’s the code, still the same problem (bold part won’t work).

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
bool flag = false;
char kk;
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;

#include <LiquidCrystal.h>
LiquidCrystal lcd( 8, 9, 10, 11, 12, 13);

#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’},
{’*’,‘0’,’#’,‘D’}
};
byte rowPins[ROWS] = {7, 6, 5, 4};
byte colPins[COLS] = {A3, A2, A1, A0};
Keypad CK = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
lcd.print(“What would you”);
lcd.setCursor(0, 1);
lcd.print(“like to do?”);
finger.begin(57600);
}

uint8_t readnumber(void) {
uint8_t num = 0;

while (num == 0) {
while (! Serial.available());
num = Serial.parseInt();
}
return num;
}

void loop() {
while(flag==false){
char customKey = CK.getKey();
Serial.print(customKey);
if(customKey){
lcd.clear();
lcd.print(customKey);
}
if(customKey==‘1’){
addFingerPrint();
}
}
}

void addFingerPrint(){
flag=true;
lcd.clear();
delay(100);
lcd.print(“Add Fingerprint”);
lcd.setCursor(0,1);
lcd.print(“Program!”);
delay(700);
lcd.clear();
lcd.print(“Ready!”);
delay(200);
lcd.clear();
lcd.print(“Insert a number!”);
lcd.setCursor(0, 1);
lcd.print("(1-127)");
kk = CK.getKey();
Serial.println(kk);
if(kk==‘5’){
lcd.clear();
lcd.print(“aaa”);
}
}

Please read the How to use this forum post and start using code tags when posting your code. Yes the forum rules even apply to you. You’re not special.

Also please press control T on the ide and format this. Lining up your blocks will often times help you spot flow errors. When you see real coders write and the blocks are all lined up nice and neat, yeah we don’t do that just to make it pretty.

Your addFingerPrint routine does not wait for anyone to press a key. So you enter a 1 and it goes to that addFingerPrint function. Now you’ve got less than a millisecond to stop pressing the 1 and start pressing the 5. Unless your name is Superman or The Flash that ain’t gonna happen.