I've managed to do it in a much simpler way, thanks for your help!
C:
int state = 0;
int delay[] = { 150, 250, 500 };
void handle_press() {
/* blink three times at the rate specified for the current state */
for (int i = 0; i < 3; ++i) {
LED1 = 1;
delay_ms(delay[state]);
LED1 = 0;
delay_ms(delay[state]);
}
/* then wait another second */
delay_ms(1000);
/* update state */
state = (state + 1);
if (state == 3) {
state = 0;
}
}
void loop() {
while (true) {
if (SW1 == 0) {
handle_press();
}
}
}