Skip to main content
added 84 characters in body
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50

You get random values because if the key is not found in getKey, then there is no return statement.

You attach the \n to the key in serialEvent(), then the key for getKey is "key1\n" and it is not found.

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    } else {
      inputString += inChar;
    }
  }
}

If you have CR/LF set in Serial Monitor, then the \r character is send too and the parsed key is "key1\r\n".

thereThere are obsolete things in your code, like the this->* or Uno::. Make the map std::map<String, int> keys;, because now you mix pointers and ints.

You get random values because if the key is not found in getKey, then there is no return statement.

You attach the \n to the key in serialEvent(), then the key for getKey is "key1\n" and it is not found.

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    } else {
      inputString += inChar;
    }
  }
}

If you have CR/LF set in Serial Monitor, then the \r character is send too and the parsed key is "key1\r\n".

there are obsolete things in your code, like the this->* or Uno::

You get random values because if the key is not found in getKey, then there is no return statement.

You attach the \n to the key in serialEvent(), then the key for getKey is "key1\n" and it is not found.

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    } else {
      inputString += inChar;
    }
  }
}

If you have CR/LF set in Serial Monitor, then the \r character is send too and the parsed key is "key1\r\n".

There are obsolete things in your code, like the this->* or Uno::. Make the map std::map<String, int> keys;, because now you mix pointers and ints.

added 143 characters in body
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50

You set CR/LF in Serial Monitor and you test \n as end of lineget random values because if the key is not found in codegetKey, then there is no return statement. and/or you

You attach the \n char to the end of key. The \r\n or \n is parsed/attached to key. The in serialEvent(), then the key for getgetKey is the "key1\r\n" or "key1\r""key1\n" and it is not found.

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    } else {
      inputString += inChar;
    }
  }
}

If you have CR/LF set in Serial Monitor, then the \r character is send too and the parsed key is "key1\r\n".

there are obsolete things in your code, like the this->* or Uno::

You set CR/LF in Serial Monitor and you test \n as end of line in code. and/or you attach the \n char to the end of key. The \r\n or \n is parsed/attached to key. The key for get is the "key1\r\n" or "key1\r"

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    } else {
      inputString += inChar;
    }
  }
}

there are obsolete things in your code, like the this->* or Uno::

You get random values because if the key is not found in getKey, then there is no return statement.

You attach the \n to the key in serialEvent(), then the key for getKey is "key1\n" and it is not found.

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    } else {
      inputString += inChar;
    }
  }
}

If you have CR/LF set in Serial Monitor, then the \r character is send too and the parsed key is "key1\r\n".

there are obsolete things in your code, like the this->* or Uno::

added 281 characters in body
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50

You set CR/LF in Serial Monitor and you test \n as end of line in code. and/or you attach the \n char to the end of key. The \r\n or \n is parsed/attached to key. The key for get is the "key1\r\n" or "key1\r"

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    } else {
      inputString += inChar;
    }
  }
}

there are obsolete things in your code, like the this->* or Uno::

You set CR/LF in Serial Monitor and you test \n as end of line in code. and/or you attach the \n char to the end of key. The \r\n or \n is parsed/attached to key. The key for get is the "key1\r\n" or "key1\r"

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    } else {
      inputString += inChar;
    }
  }
}

You set CR/LF in Serial Monitor and you test \n as end of line in code. and/or you attach the \n char to the end of key. The \r\n or \n is parsed/attached to key. The key for get is the "key1\r\n" or "key1\r"

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    if (inChar == '\n') {
      stringComplete = true;
    } else {
      inputString += inChar;
    }
  }
}

there are obsolete things in your code, like the this->* or Uno::

added 281 characters in body
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50
Loading
added 85 characters in body
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50
Loading
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50
Loading