In my ST32L c
application I want to speed up the blinking LEDs. With the code below I can press the button and the LEDs will blink faster. When I release, the LEDs will blink normal.
How can I check if a button is pressed for minimal 2 seconds and after that speed up the LEDs?
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;
}
}
}