unsigned long startTime = 0;
unsigned long interval = 500; // 1 second
int counter = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  unsigned long currentTime = millis();

  if (currentTime - startTime >= interval) {
    counter++;
    Serial.println(counter);
    startTime = currentTime;
  }

  if (counter>5) counter=0;

  // put your main code here, to run repeatedly:
}