在方法之间传递整数会导致其更改

时间:2018-12-22 21:09:27

标签: c++ arduino

所以我一直在玩我的Arduino,遇到了一些奇怪的事情。我有以下代码:

void loop() 
{
    selector(1, 20000);
}
selector(int mode, int timeInterval)
{
    if(mode == 1){
        survey(timeInterval);
    }
}
void survey(int timeToWait)
{
    newMillis = currentMillis;
    while (newMillis - currentMillis <= timeToWait) {
        Serial.println(timeToWait);
        //Do something else
    }
}

如果运行上面的代码,则串行监视器将打印出-5536。

但是,如果我执行survey(timeInterval);,则我的串行监视器将打印出20000。

我在这里忽略了什么吗?而我该怎么办?

1 个答案:

答案 0 :(得分:1)

您在这里犯了一个错误

{
    ...
    [MarshalAs(UnmanagedType.I1)]
    public bool Persist;
    ...
}

我想你的意思

if(mode = 1){