title: How to program Arduino to take and save two keypad inputs in separate variables?
body: <p>Trying to make a simple Arduino adder but I am having trouble with the programming. I am not sure where I made a mistake. Any help would be much appreciated.</p>
  
  <p>The user would have to enter two numbers n a keypad and their sum would be displayed on an LCD. Each of the two numbers entered by the user are stored in their variables respectively. The problem is that after entering the first number the program automatically plugs in 0 (since no key is pressed at that moment) for the second variable. I have tried 'if', 'while' and 'do while' statements to eliminate NO_KEY but none of these seem to be working. </p>
  
  <p>The question is if there is a way to store a number entered by the user in a variable and not let the program overwrite it with 0 because no key is being pressed at that moment. Or also, to not let the Arduino receive any more inputs from the keypad after a key is pressed (maybe disable the keypad somehow)...</p>
  
  <p>If you are willing to spend some time on looking over the code, the website linked <a href="https://circuits.io/circuits/2498139-calculator/embed#breadboard" rel="nofollow">here</a> contains both the code and the whole lab setup.</p>
  
  <pre><code>#include &lt;Keypad.h&gt;
  #include &lt;LiquidCrystal.h&gt;
  
  LiquidCrystal lcd (7,8,9,10,11,12);
  int backLight(13);
  
  
  int Addition(int x, int y){
      int z;
      z = x+y;
      lcd.setCursor(8,0);
      lcd.write(z);
  }
  
  void setup() {
  
  }
  
  const byte rows =4;
  const byte cols =3;
  
  char keys[rows][cols]={
      {'1','2','3'},
      {'4','5','6'},
      {'7','8','9'},
      {'*','0','#'}
  };
  
  byte rowPins[rows] = {0,1,2,3};
  byte colPins[cols] = {4,5,6};
  
  Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
  
  
  void loop(){
  
      int a;
      int b;
  
      a = keypad.getKey();
      if (a != NO_KEY){
  
          do {
              b = keypad.getKey();
          }while (b == NO_KEY);
  
          pinMode (backLight, OUTPUT);
          digitalWrite(backLight, HIGH);
          lcd.begin(16,2);
          lcd.clear();
  
          lcd.setCursor(0,0);
          lcd.write(a);
  
          lcd.setCursor(2,0);
          lcd.write("+");
  
          lcd.setCursor(4,0);
          lcd.write(b);
  
          lcd.setCursor(6,0);
          lcd.write("=");
  
          Addition(a,b);
          delay(10000);
  
      }
  
  }
  </code></pre>