Entering numbers at the Serial Monitor
hello all,
i'm using uno + xbee series 1 + lcd mirror reading @ gas meter - difficulty in reading thing sited. real novice here, have managed going point hall sensor @ meter picks each dial rotation , adds lcd display in house. real readings displayed, need input 9 digit number "offset" incoming pulses added.
i playing around published sketches (thank you) code below.
i have changed of text messages , added 1 calculation (*2).
if enter 999999999 (i.e.9 digits), ok - if tenth digit added, overflows.
can tell me why happens, , significance of "overflow" number comes on serial monitor?
thanks
i'm using uno + xbee series 1 + lcd mirror reading @ gas meter - difficulty in reading thing sited. real novice here, have managed going point hall sensor @ meter picks each dial rotation , adds lcd display in house. real readings displayed, need input 9 digit number "offset" incoming pulses added.
i playing around published sketches (thank you) code below.
code: [select]
int incomingbyte = 0; // incoming serial data
string instring = ""; // string hold input
void setup() {
// put setup code here, run once:
serial.begin(9600); // opens serial port, sets data rate 9600 bps
serial.print ("enter data @ command line , check set newline");
serial.print("\n");//needs display "value" , "string" - if omitted, displays "string" first time round
}
void loop() {
// put main code here, run repeatedly:
// send data when receive data:
if (serial.available() > 0) {
// read incoming byte:
incomingbyte = serial.read();
if (isdigit(incomingbyte)) {
// convert incoming byte char
// , add string:
instring += (char)incomingbyte;
}
if (incomingbyte == '\n') {
serial.print("value:");
serial.println(instring.toint()*2);
serial.print("string: ");
serial.println(instring);
// clear string new input:
instring = "";
}
}
}
i have changed of text messages , added 1 calculation (*2).
if enter 999999999 (i.e.9 digits), ok - if tenth digit added, overflows.
can tell me why happens, , significance of "overflow" number comes on serial monitor?
thanks
quote
int incomingbyte = 0; // incoming serial data
why? if name implies byte, why type not byte? use name implies.
code: [select]
if (isdigit(incomingbyte)) {
isdigit() expects char.
code: [select]
// convert incoming byte char
// , add string:
instring += (char)incomingbyte;
another clue correct type variable.
quote
if enter 999999999 (i.e.9 digits), ok - if tenth digit added, overflows.
have looked @ documentation toint() method? despite stupid name, not return int. 10 character value trying enter fit in variable of type toint() returns?
there reason reference page. expected use it.
Arduino Forum > Using Arduino > Programming Questions > Entering numbers at the Serial Monitor
arduino
Comments
Post a Comment