0 c microcontroller if-statement ternary-operator
因此,在查看大规模的互联网后,我无法找到答案.
说我有这段代码:
if(P4IN & GPIO_PIN1?0:1){
if (state==1){
state = 0;
//Wait for this state to pass -- ends up saving the current state on button press.
while (counter < 10000){
counter++;
}
}
else{
state = 1;
while (counter < 10000){
counter++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么会重写这个,所以if(P4IN & GPIO_PIN1?0:1)不是这样写的.我不介意创建额外的if/else条件或扩展此代码块(用于MSP432)
谢谢你的时间.
您可以简化整个过程:
if (!(P4IN & GPIO_PIN1)) {
state = !state;
while (counter < 10000) {
counter++;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
88 次 |
| 最近记录: |