23 ASCII is a non-printing control character.
You're going to have to do more work to input and convert 0x32 and 0x33 into 23, if that's what you're trying to do.
TheMemberFormerlyKnownAsAWOL:
23 ASCII is a non-printing control character.
You're going to have to do more work to input and convert 0x32 and 0x33 into 23, if that's what you're trying to do.
Use Serial.parseInt() instead of Serial.read(). WARNING: If you call Serial.parseInt() and no number arrives within the timeout period (default: 1 second) it will return 0. One solution is to empty the input buffer before prompting for an answer and then waiting for a character to arrive:
int number = 23;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available()) Serial.read(); // Flush
Serial.println("Guess a number");
while (!Serial.available()) {} // Wait for response
int c = Serial.parseInt();
if (c == number)
{
Serial.println("correct");
}
else
{
Serial.print(c);
Serial.println(" is not correct, try again");
}
}