1

Using a 4x3 membrane keypad and I want to make the '*' key a backspace if the wrong number is entered.

I am a newbie and having a hard time trying to figure out how to code that, any help would be great.

int getNumber()
{
  int num = 0;
  char key = myKeypad.getKey();
  while (digitCount <=  1)
  {
    switch (key)

    {
    case NO_KEY:
      break;
    case '0':     
    case '1':     
    case '2':     
    case '3':     
    case '4':    
    case '5': 
    case '6':     
    case '7':     
    case '8':     
    case '9':
      num = num * 10 + (key -  48);
      digitCount++;
      break;
    case '*':
      break;
    case '#':
      break;
    }
  key = myKeypad.getKey();
  }

  digitCount = 0;
  return num;
}
  • 7
    Divide your number by 10? – Majenko Sep 25 '18 at 15:12
  • Sorry, don't understand what you mean. – Mark Savoia Sep 25 '18 at 20:03
  • To make room to add a number you multiply by Ten. So to remove that space you divide by 10. – Majenko Sep 25 '18 at 20:07
  • case '*': num /= 10; break; and then you need to echo that to the display (if any). – Mikael Patel May 24 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.