void setup() {
  Serial.begin(115200);
  Serial.println("rdy");
}

int val;
void cmds () {
  if (Serial.available()) {
      char c = Serial.read();

      switch (c)  {
      case '0':
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
          val = 10*val + c - '0';
          break;

      case 'a':
          Serial.println(val);
          val = 0;
          break;
      }
  }
}

void loop() {
  cmds ();
}