Hello guys, I am working on a project which is based on Arduino mega 2560. I am interfacing the 4*4 matrix keypad with arduino board and taking inputs from keypad. I want to increment a counter when the key is pressed and do nothing when the key is released, i.e. as long as I hold the key in pressed mode it should increment the counter. However, I am not able to do so. I have used keypad library functions and tried many things but it didn't work. I am attaching my code. Please help me.
I have tried to check the response on a serial monitor. It shows nothing. Logically program seems correct as state and key are the two inputs we are getting from the keypad. I have also tried one condition at a time like as follows:
if (key=='1'){
counter=counter+1;
Serial.println(counter);
}
In this case it incremented the counter, but every time i had to press and release the key to increment it by 1.
In this code it incremented the counter whenever the key is pressed continuously which is exactly the result i expected. But it is doing the same for all the keys, i.e. even if i press '2' continuously it kept the counter incrementing.
Some code you didn't post does something you didn't explain. You expected the code to do something. All that we know at this point is that what the code did is not what you expected.