void SD2(){ static State state = INITIAL; static uint32_t previousTime = 0; if(pushButton() == 1) delay500ms = 100; else delay500ms = 500; switch(state){ case INITIAL: turnOnLED2(); if(delay(delay500ms, previousTime)){ state = LEDON; previousTime = currentTime; } break; case LEDON: turnOnLED2(); if(delay(delay500ms, previousTime)){ state = LEDOFF; previousTime = currentTime; } break; case LEDOFF: turnOffLED2(); if(delay(delay500ms, previousTime)){ state = LEDON; previousTime = currentTime; } break; } }
void runningLight(State *state, int time){ static int previousTime = 0 ; switch(*state){ case INITIAL: turnOffLED1(); turnOffLED2(); turnOffLED3(); turnOffLED4(); *state = LED1_ON; break; case LED1_ON: if( waitWithoutDelay( previousTime,time) ){ previousTime = getCurrentTime(); turnOnLED1(); turnOffLED4(); *state = LED2_ON; } break; case LED2_ON: if( waitWithoutDelay( previousTime,time) ){ previousTime = getCurrentTime(); turnOnLED2(); turnOffLED1(); *state = LED3_ON; } break; case LED3_ON: if( waitWithoutDelay( previousTime,time) ){ previousTime = getCurrentTime(); turnOnLED3(); turnOffLED2(); *state = LED4_ON; } break; case LED4_ON: if( waitWithoutDelay( previousTime,time) ){ previousTime = getCurrentTime(); turnOnLED4(); turnOffLED3(); *state = LED1_ON; } break; default : break; } }