Serial.parseInt() problem - (solved)

OK simple job to do but as always result is not as expected and my friend google did not helped.

In serial monitor I type "R1234" and send it. The variable with 350 need to be overwritten by 1234.

But for some reason it does not with my code. It starts with 350 as expected It receives 1234 and prints it Then it returns to 350 >:(

Any suggestion what goes wrong?

Paco

long LoadBRX;

void setup() 
{
  Serial.begin(9600);
  LoadBRX = 350;
}

void loop() 
{
  if (Serial.available() > 0) // check if we have data
  {
    LoadBRX = Serial.parseInt();  // read the typed serialmonitor "R1234" value into the variable
    if (LoadBRX >= 1) // do something if the value is larger then 1
    {
      Serial.println(LoadBRX); // print the received 1234 value in the serial monitor
      LoadBRX = LoadBRX;  // set the variable to the new recieved value
    } 
  }
  Serial.println(LoadBRX); // print the value of the variable
  delay(500);
}

It starts with 350 as expected It receives 1234 and prints it Then it returns to 350

Not for me it doesn't, but I do wonder why you think that this line is necessary,

     LoadBRX = LoadBRX;  // set the variable to the new recieved value

What is the value of LoadBRX before and after it ?

Bob,

I just checked again the code and now it works. :smiling_imp: Did not changed anything as the serial monitor of my last try was still open...........!.

You correct that line is of no use.

Anyway LoadBRX started with 350 and after 1234 it reverted back to 350 so the 1234 was not taken over in the variable as new value. But now it does, so strange.

thanks for checking.

Paco