Hello All,
I'm using a Uno + XBee Series 1 + LCD to mirror the reading at a gas meter - this is mainly to do with the difficulty in reading the thing where it is sited. As a real novice here, I have managed to get everything going to the point where the Hall sensor at the meter picks up each dial rotation and adds it to the LCD display in the house. To get real readings displayed, I need to input a nine digit number which is the "offset" to which the incoming pulses are added.
I was playing around with some published sketches (thank you) with the code below.
int incomingByte = 0; // for incoming serial data
String inString = ""; // string to hold input
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
Serial.print ("enter data at command line and check that set to NEWLINE");
Serial.print("\n");//needs this to display "value" and "string" - if omitted, displays "string" only first time round
}
void loop() {
// put your main code here, to run repeatedly:
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
if (isDigit(incomingByte)) {
// convert the incoming byte to a char
// and add it to the string:
inString += (char)incomingByte;
}
if (incomingByte == '\n') {
Serial.print("Value:");
Serial.println(inString.toInt()*2);
Serial.print("String: ");
Serial.println(inString);
// clear the string for new input:
inString = "";
}
}
}
I have only changed some of the text messages and added one calculation (*2).
If I enter 999999999 (i.e.9 digits), everything is OK - if a tenth digit is added, it overflows.
Can someone tell me why it happens, and what is the significance of the "overflow" number that comes up on the Serial Monitor?
Thanks