내 ST32L c
애플리케이션에서 깜박이는 LED의 속도를 높이고 싶습니다. 아래 코드를 사용하면 버튼을 누르면 LED가 빠르게 깜박입니다. 놓으면 LED가 정상적으로 깜박입니다.2 초 후에 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;
}
}
}