This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Key de-bouncing in 4x4 matrix keypad

I'm using 4 x 4 keypad to send the output to 2 7-segment LED.

problem: key de bouncing problem

Summary problem: when I press key, it shows both digit on the left and right. For example, if I first press 1, it should show 1 on the right and blank on the left. If I press 3 next, it should show 1 on the left and 3 on the right. Right now, it I press 1 it shows 1 on the left and 1 on the right. I think this relate to key debouncing. Please check my code.

void read(void) {

char left_val = 'n';

char right_val = 'n';

char next_val = readKeyPad();

while(1){

next_val = readKeyPad();

if (right_val == next_val || next_val == 'n'){

printChar(left_val, Left);

delay(FRAME_PERIOD);

printChar(right_val, Right);

delay(FRAME_PERIOD);

}

else {

left_val = right_val;

right_val = next_val;

}

}
}

Parents
  • void read(void){ char left_val = 'n'; char right_val = 'n'; char next_val = readKeyPad(); while(1) { next_val = readKeyPad(); if (right_val == next_val || next_val == 'n') { printChar(left_val, Left); delay(FRAME_PERIOD); printChar(right_val, Right); delay(FRAME_PERIOD); } else { left_val = right_val; right_val = next_val; } }}

    Code is WAY too complicated for my simple brain to comprehend.

Reply
  • void read(void){ char left_val = 'n'; char right_val = 'n'; char next_val = readKeyPad(); while(1) { next_val = readKeyPad(); if (right_val == next_val || next_val == 'n') { printChar(left_val, Left); delay(FRAME_PERIOD); printChar(right_val, Right); delay(FRAME_PERIOD); } else { left_val = right_val; right_val = next_val; } }}

    Code is WAY too complicated for my simple brain to comprehend.

Children