输出不符合预期

Output doens't come out as expected

我尝试添加一个布尔数组来存储用户的当前状态。 这是我的数组:

bool enterStatus[5];

稍后在代码中,我将根据获得的 ID 检查数组,如果 ID 为假,则将其设置为真,反之亦然。

假设id为1,

if(enterStatus[id] == true){
  enterStatus[id] = false;
} if(enterStatus[id] == false){
  enterStatus[id] = true;
}
Serial.print(enterStatus[id]);

这就是我的尝试。 我得到的输出:

11111111111111111111111111111111

我希望循环输出为:

1010101010101010101010101

我哪里做错了?请纠正我。提前致谢。

你的 if 是错误的,因为你检查 true 是否设置为 false,然后如果 false(现在已经确定),将会设置为 true。请在第二个 if

前加一个 else