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; } }
void SD3(){ static State state = INITIAL; static uint32_t previousTime = 0; static int counter = 0; switch(state){ case INITIAL: counter = 0; turnOffLED3(); turnOffLED4(); if(pushButton() == 1){ state = LEDON; previousTime = currentTime; } break; case LEDON: turnOnLED3(); turnOnLED4(); if(delay(100, previousTime)){ state = LEDOFF; previousTime = currentTime; counter++; } break; case LEDOFF: turnOffLED3(); turnOffLED4(); if(delay(100, previousTime)){ state = LEDON; previousTime = currentTime; } if(counter > 5) state = INITIAL; break; } }
int main(void) { initControl(); initLED1(); initLED2(); initLED3(); initLED4(); while(1) { turnOnLED2(); if(switchControl() == GPIO_PIN_SET) { turnOnLED4(); if(Ethernet_Init() == 1) { HAL_ETH_Start(&heth); blink_LED1(); } turnOffLED4(); } } }