// Definisi pin LED
const int led1 = 2;
const int led2 = 3;
const int led3 = 4;
const int led4 = 5;
const int led5 = 6;

// Definisi pin tombol
const int button1 = 7;
const int button2 = 8;
const int button3 = 9;

// Variabel untuk melacak status tombol dan LED
bool toggleState = false; // Status untuk toggle semua LED
bool button3PrevState = false; // Status tombol 3 sebelumnya

void setup() {
  // Set pin LED sebagai output
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);

  // Set pin tombol sebagai input dengan pull-up
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
}

void loop() {
  // Baca status tombol
  bool button1State = digitalRead(button1) == LOW; // LOW berarti tombol ditekan
  bool button2State = digitalRead(button2) == LOW;
  bool button3State = digitalRead(button3) == LOW;

  // Tombol pertama: nyalakan LED ganjil (1, 3, 5)
  if (button1State) {
    digitalWrite(led1, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led5, HIGH);
  }

  // Tombol kedua: nyalakan LED genap (2, 4)
  if (button2State) {
    digitalWrite(led2, HIGH);
    digitalWrite(led4, HIGH);
  }

  // Tombol ketiga: toggle semua LED (mati -> nyala -> mati)
  if (button3State && !button3PrevState) { // Deteksi tombol ditekan
    toggleState = !toggleState; // Toggle status semua LED

    // Atur LED sesuai status toggle
    digitalWrite(led1, toggleState ? LOW : HIGH);
    digitalWrite(led2, toggleState ? LOW : HIGH);
    digitalWrite(led3, toggleState ? LOW : HIGH);
    digitalWrite(led4, toggleState ? LOW : HIGH);
    digitalWrite(led5, toggleState ? LOW : HIGH);
  }

  // Simpan status tombol 3 sebelumnya
  button3PrevState = button3State;
}