You are going to get ASCII representation codes on Key stroke inputs , You will understand more on reading about ASCII values on respective Key Strokes, Google for it.
There are two drop-downs at the bottom of the serial monitor. One of them selects what is sent at the end of whatever you type. It might say 'Newline', or 'Carriage return' currently. Try changing it to 'No line ending'.
If that doesn't work, you'll need a different terminal program.
but now it reads only one digit. So if I type 10, I get :
It will. You are reading one character and printing it back. If you want to read multi-character strings, you'll need to construct them in your sketch.
but now it reads only one digit. So if I type 10, I get :
I received: 1
I received: 0
what should I change?
PS: Thanks dxw00d
You need start and stop bytes to know when you start receiving a new number and when you're done imputing an number in. Most people commonly use '<' and '>'. You read that into a buffer and then you can convert it to a number.
int incomingByte = 0; // for incoming serial data
String inString = ""; //to store serial data
void setup() { Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
while (Serial.available() > 0) {
incomingByte = Serial.read();
inString += (char)incomingByte; //add data to string
}
if (inString != ""){ //if the string isn't empty...
// say what you got: Serial.print("I received: "); Serial.println(inString);
inString = ""; //clear string for new input
}
}