Why is there a delay when i pressed my keypad

Hi, i hope you guys doing well. So my problem is if i pressed 1 and the button isn't being pressed it will be output as A. And if i pressed 1 and the button is pressed it will be output B. but in my condition when i pressed 1 i need to pressed many time to output an A, there is like a delay. i have tried many times, is it because

Are you using delay() in your code?
We can't see your code. We can't see your wiring.

How about a schematic, not a frizzy thing with links to the hardware items showing technical detail. groundFungus nailed it, without code we do not have a chance of helping you. What is it outputting to and how do you know it is or is not?

oh sorry, this the code

////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Key.h>
#include <Keypad.h>

#include <LiquidCrystal_I2C.h>

byte buttonPin = 13;

LiquidCrystal_I2C lcd(0x27, 16, 2);

const byte ROWS = 4;
const byte COLS = 4;

char keys [ROWS] [COLS] = {
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'C', '0', '=', '/'}
};
//pin dari keypad 4x4
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8, 9};

Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
lcd.init();
lcd.backlight();
pinMode(buttonPin, INPUT);

}
void loop() {
char key = myKeypad.getKey();
//For delete all text
if (key == 'C') {
lcd.clear();
}
//for space between words
else if(key == '/'){
lcd.print(" ");
}
//calling function
shiftOff('1', 'A');
shiftOn('1', 'B');
}

void shiftOff(char numPressed, char alphabet){
if(myKeypad.getKey() == numPressed && digitalRead(buttonPin) == 0 ){
lcd.print(alphabet);
}
}

void shiftOn(char numPressed2, char alphabet2){
if(myKeypad.getKey() == numPressed2 && digitalRead(buttonPin) == 1){
lcd.print(alphabet2);
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
its very simple

for the wiring
the button is connect to pin 13
the keypad rows are connect to pin 2 to 5
the columns are connected to pin 6 to 9
and the lcd I2C is connected to pin SLC and SDA

its outputting A as i expect it but, i have to press many times to output an A, it keeps delaying or lagging. sometimes if i press it the output will not come out

A schematic drawing is preferred over a written description.

Does the button switch have a pulldown or pullup resistor?

The better way to wire a button switch is to wire one side of the switch to ground and the other to an input pin with the pinMode set to INPUT_PULLUP. The switch will read HIGH when not pressed and LOW when pressed. Adjust the logic in your code accordingly.

I can see potential for race or no-effect in your shiftxx functions which would lead to nothing happening.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.