// Define pin assignments
const int buttonStartPin = 2;
const int buttonStopPin = 3;
const int ledStarPin = 4;
const int ledDeltaPin = 5;
const int ledOffPin = 6;
const int relayStarPin = 7;
const int relayDeltaPin = 8;

enum State {
  OFF,
  STAR,
  DELTA
};

State currentState = OFF;

void setup() {
  // Initialize pins
  pinMode(buttonStartPin, INPUT_PULLUP);
  pinMode(buttonStopPin, INPUT_PULLUP);
  pinMode(ledStarPin, OUTPUT);
  pinMode(ledDeltaPin, OUTPUT);
  pinMode(ledOffPin, OUTPUT);
  pinMode(relayStarPin, OUTPUT);
  pinMode(relayDeltaPin, OUTPUT);

  // Set initial state to OFF
  setState(OFF);
}

void loop() {
  // Read button states
  bool buttonStartPressed = digitalRead(buttonStartPin) == LOW;
  bool buttonStopPressed = digitalRead(buttonStopPin) == LOW;

  // Handle start button press
  if (buttonStartPressed && currentState == OFF) {
    setState(STAR);
    delay(5000); // Simulate delay for star to delta transition (adjust as needed)
    setState(DELTA);
  }

  // Handle stop button press
  if (buttonStopPressed && (currentState == STAR || currentState == DELTA)) {
    setState(OFF);
  }
}

void setState(State newState) {
  currentState = newState;
  switch (currentState) {
    case OFF:
      digitalWrite(ledStarPin, LOW);
      digitalWrite(ledDeltaPin, LOW);
      digitalWrite(ledOffPin, HIGH);
      digitalWrite(relayStarPin, LOW);
      digitalWrite(relayDeltaPin, LOW);
      break;
    case STAR:
      digitalWrite(ledStarPin, HIGH);
      digitalWrite(ledDeltaPin, LOW);
      digitalWrite(ledOffPin, LOW);
      digitalWrite(relayStarPin, HIGH);
      digitalWrite(relayDeltaPin, LOW);
      break;
    case DELTA:
      digitalWrite(ledStarPin, LOW);
      digitalWrite(ledDeltaPin, HIGH);
      digitalWrite(ledOffPin, LOW);
      digitalWrite(relayStarPin, LOW);
      digitalWrite(relayDeltaPin, HIGH);
      break;
  }
}