即使我的 if 语句成立,我也遇到了麻烦

I am having trouble with my if statement holding true even when it is

我的 AltCheckInt 声明不成立。它从 9999-33000 开始工作,然后切换到 false,在 55000 时再次切换回 true,然后由于某种未知原因在 70000 时再次切换到 false。 com 的值为 SPEED 34482。有人看到我没看到的东西吗?

void AltDisplay(String com){

String AltCheckStg;
int AltCheckInt;
String Action;
String Status;
int StatusInt;
Action = com.substring(0,6);
if (Action == "SPEED "){
    Status = com.substring(6,10);
    AltCheckStg = com.substring(6,18);
    AltCheckInt = AltCheckStg.toInt();
    StatusInt = Status.toInt();
    Serial.println(AltCheckInt); 
    if(AltCheckInt >= 9999){
      digitalWrite(7, HIGH);
      StatusInt = StatusInt/100;
    }
    s7s.write(0x77);
    s7s.write(0b0000001);
    s7s.print(StatusInt);
    delay(500);
    s7s.write(0x76);
    digitalWrite(7, LOW);
    }
}

Arduino 是 16 位的,这意味着最大值 int can hold is 32,767. Due to integer overflow,32,767 之后的下一个值是 -32,768。

如果您想要更大的范围,您可能需要切换到 long

值得注意的是toInt()已经returns一个long,所以你需要做的就是改变AltCheckInt的类型。

AltCheckInt is an Integer , Which Consume 2 byte ( 16 bit) Value Rang for integer is (+_2 power 15) = 32,767 to -32,768

after crossing the limit it gives error,,,

Change AltCheckInt to any big datatype Like : __int64 ,long long, unsigned long long

Select datatype according to your requirement

Table About Datatypes in C++ with Memory & Rang Comparison

,