在我的 ST32Lc
应用程序中,我想加快闪烁 LED 的速度。使用下面的代码,我可以按下按钮,LED 会更快地闪烁。当我松开时,LED 会正常闪烁。
如何检查按钮是否被按下至少 2 秒,然后加快 LED 的速度?
int i = 0;
while (1) {
bool wasSwitchClosedThisPeriod = false;
while (i++ < speed) {
// Poll the switch to see if it is closed.
// The Button is pressed here
if ((*(int*)(0x40020010) & 0x0001) != 0) {
wasSwitchClosedThisPeriod = true;
}
}
// Blinking led
*(int*) (0x40020414) ^= 0xC0;
i = 0;
if (wasSwitchClosedThisPeriod) {
speed = speed * 2;
if (speed > 400000) {
speed = 100000;
}
}
}