Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with this problem. I am trying to show two digits on 7 segment di

ID: 3871408 • Letter: P

Question

Please help me with this problem. I am trying to show two digits on 7 segment display. For example if I press the keypad number 3, and number 6, the 7-segment display will show both number 3 on the left and 6 on the right. If I press 1, the 7 segment will show 6 and 1. Basically, it only shows the last two number. My code is working right but there is a small problem if I press 3 and 6 and 6, it supported to show 6 and 6 on the 7-segment. My code still show 3 and 6. Please help me to fix the code.

void read(void) {
char leftSide = 'n';
char rightSide = 'n';
char next = readKeyPad();

  
while(1) {
if (next == rightSide || next == 'n'){
  
printChar (leftSide, Left);
delay(FRAME_PERIOD);
printChar (rightSide, Right);
delay(FRAME_PERIOD);   
}
else{
leftSide = rightSide;
rightSide = next;
}
next = readKeyPad();
}
  
}

Explanation / Answer

void read(void) {
char leftSide = 'n';
char rightSide = 'n';
char next = readKeyPad();
  
while(1) {
if(rightSide == 'n'){
printChar (next, Right);
delay(FRAME_PERIOD);
rightSide = next;
}

else {
  
printChar(next, Right);
delay(FRAME_PERIOD);
printChar(rightSide, Left);
delay(FRAME_PERIOD);
leftSide = rightSide;

rightSide = next;
  
}
  
next = readKeyPad();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote