const int LED_PIN = 12;
const unsigned long BLINK_RATE[] = {500, 1000, 500};
bool ledState = false;
unsigned long prevTime = 0;
bool blinkLed(unsigned long speed, int number) {
bool isDone = false;
static int count = 0;
if (millis() - prevTime >= speed) {
ledState = !ledState;
digitalWrite(LED_PIN, ledState);
count++;
if (count >= number * 2) {
count = 0;
isDone = true;
} else {
//isDone = false;
}
prevTime = millis();
}
return isDone;
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
//static bool isDone = false;
for (int i = 0; i < 3; i++) {
Serial.println(i);
bool isDone = false;
do {
isDone = blinkLed(BLINK_RATE[i], 3);
}
while (!isDone);
}
}