Hi everyone,
Been at this all day and just can't seem to be able to make this work.
I'm trying to receive a 2 digit integer from the serial monitor and save it to a variable.
My code works great for my bluetooth serial connection, but causes it to hang when i try to enter a value through the terminal.
if (BTserial.available() > 0) { // something came across serial
integerValue = 0; // throw away previous integerValue
while (1) { // force into a loop until 'n' is received
incomingByte = BTserial.read();
if (incomingByte == '.') break; // exit the while(1), we're done receiving
if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1
integerValue *= 10; // shift left 1 decimal place
// convert ASCII to integer, add, and shift left 1 decimal place
integerValue = ((incomingByte - 48) + integerValue);
SetPoint = integerValue;}
BTserial.print("SetPoint is now ");
BTserial.print(SetPoint);
BTserial.println("Deg F");
Serial.print("SetPoint is now ");
Serial.print(SetPoint);
Serial.println("Deg F");
}
if (Serial.available() > 0) { // something came across serial
integerValue = 0; // throw away previous integerValue
incomingByte = 0;
while (1) { // force into a loop until 'n' is received
incomingByte = Serial.read();
if (incomingByte == '.') break; // exit the while(1), we're done receiving
if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1
integerValue *= 10; // shift left 1 decimal place
// convert ASCII to integer, add, and shift left 1 decimal place
integerValue = ((incomingByte - 48) + integerValue);
SetPoint = integerValue;
if (SetPoint > 100) {
SetPoint = 70;
}
}
BTserial.print("SetPoint is now ");
BTserial.print(SetPoint);
BTserial.println("Deg F");
Serial.print("SetPoint is now ");
Serial.print(SetPoint);
Serial.println("Deg F");
}