#include <TimerOne.h>

const int jumlahLed = 10; // Jumlah LED
int pinLed[jumlahLed] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; // Pin LED

int ledIndex = 0; // Indeks LED yang sedang menyala

int cd_minute;
int cd_sec;
int millsec;
int millsecMod;
byte i;

void setup() {
  // Inisialisasi timer
  Timer1.initialize(1000); // 1 detik
  Timer1.attachInterrupt(timerIsr); // Lampirkan ISR

  // Inisialisasi serial
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  // Inisialisasi LED
  for (int i = 0; i < jumlahLed; i++) {
    pinMode(pinLed[i], OUTPUT);
    digitalWrite(pinLed[i], LOW);
  }
}

void loop() {
  // Tidak ada yang perlu dilakukan di loop utama
  delay(1000);
  Serial.println("ok");
}

void timerIsr() {

  millsec++;
  if (millsec >= 1000) {
    millsec = 0;
    cd_sec++;
    static bool ledOn = false; // Status LED
    ledOn = !ledOn;
    digitalWrite(13, ledOn);
  } else if (cd_sec > 59) {
    cd_sec = 0;
    millsec = 0;
    cd_minute++;
  } else if (cd_minute > 59) {
    cd_sec = 0;
    millsec = 0;
  }
  //-------sec mod
  millsecMod++;
  if (millsecMod >= 100) {
    millsecMod = 0;
    //---------------------------
    if ( i < jumlahLed) {
      digitalWrite(pinLed[i], HIGH);  // Nyalakan LED
      i++;
    } else {
      for (byte j = 0; j < jumlahLed; j++) {
        digitalWrite(pinLed[j], LOW);  // Matikan LED
      }
      i = 0;
    }

  }

}