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: 3871357 • 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 1, and number 2, the 7 segment display will show both number 1 and 2. If I press 3, the 7 segment will show 2 and 3. Only showing the last two number. My code is working but if I press 2 and 3 and 3, it supported to show 3 and 3 on the 7 segment. My code still show 2 and 3. 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

This is the some chnages i have done to work 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+1;
}
next = readKeyPad();
}
  
}  

Its working for me

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