UKHeliBob:
while (FloatRad < 25.225);
How is FloatRad ever going to change once in this while loop ?
I have a measuring device sending serial messages repeatedly about twice a second with rs232 this is then converted with a RS232 to ttl converter, the chars received are then put into a string & then converted to a float to make it compatible with my while loop. My thoughts were FloatRad's values would change as the measuring device sends new values, when the measuring device reaches this condition it would jump out the loop to turn off the motor. Plus think I need to work on my syntax 
Same question even if you remove the semicolon, just that there is more code in the while loop
Not actually a problem but note my questions in the comments
{ // wny is this here ?
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(enA, 0);
} // and this ?
Hi UKHelibob thanks for taking a look. This looks like it could be a classic noob syntax error, I've given it an edit, hopefully it has improved.
// Reads chars into a String until newline '\n'
//#include <Metro.h>
int enA = 9;
int in1 = 8;
int in2 = 7;
String sylvacRad;
float FloatRad;
void setup() {
Serial.begin(9600);
for (int i = 10; i > 0; i--) {
Serial.print(' '); Serial.print(i);
delay(500);
}
Serial.println();
Serial.println(F("readStringUntilLimitedTimeout.ino"));
sylvacRad.reserve(20); // expected line size, CR + LF sylvac
}
// read Serial until until_c char found or limit char read or timeout, returns true when found/limited else false
// non-blocking, until_c, if found, is returned as last char in String, updates input String with chars read
bool readStringUntil(String& sylvacRad, char until_c, size_t char_limit) { // call with char_limit == 0 for no limit
static bool timerRunning; static unsigned long timerStart; // timeout static variables
static const unsigned long timeout_mS = 1000; // 1sec set to 0 for no timeout
while (Serial.available()) {
timerRunning = false; // set true below if don't return first
char c = Serial.read();
sylvacRad += c;
if (c == until_c) {
return true;
}
if (char_limit && (sylvacRad.length() >= char_limit)) {
return true;
}
// restart timer running
if (timeout_mS > 0) { // only start if we have a non-zero timeout
timerRunning = true;
timerStart = millis();
}
}
if (timerRunning && ((millis() - timerStart) > timeout_mS)) {
timerRunning = false;
return true;
}
return false;
}
char terminatingChar = '\n';
void loop() {
ReadSerial(); //Serial to TTL to Char to String
DriveMotor(); //loop conditions for F type cartridge
}
void ReadSerial() {
if (readStringUntil(sylvacRad, terminatingChar, 20)) { // read until find newline or have read 20 chars, use 0 for unlimited no chars
if (sylvacRad.lastIndexOf(terminatingChar) >= 0) { // could also use check if (input[input.length()-1] == terminatingChar)
sylvacRad.remove(0, 2);
float FloatRad = sylvacRad.toFloat();
//Serial.print(sylvacRad);
Serial.print(FloatRad, 4);
} else {
Serial.print(F(" reached limit or timeout without newline '")); Serial.print(sylvacRad); Serial.println("'"); Serial.print(FloatRad);
}
sylvacRad = ""; // clear after processing for next line
}
}
void DriveMotor() {
while (FloatRad < 25.225) { //while sylvacRad is not at its maximum setting, drive up
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, 255);
} //when FloatRad reaches its condition, jump onto next line
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(enA, 0); //turn motor off to allow autoIT to do its magic
delay (3000); //delay for maximum amount of time to reach top + to change gain & offset
while (FloatRad > 24.885) { //while sylvacRad is not at its minimum, drive down
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enA, 255);
}
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(enA, 0);
delay (3000);
}
Problem is I'm still only getting a single reading, see photos labelled singlereading and repeatedresult. Because I am only getting a single reading I'm thinking this is why FloatRad won't change.
I thought at least the motor would run though, just the variable wouldn't change so it would run forever. Is this because I need to implement some multi-tasking? Thanks again