// Constants for input pins
const int parkPin = 2;
const int intermittentPin = 3;
const int lowPin = 4;
const int highPin = 5;

// Constants for output pins
const int lowRelayPin = 6;
const int highRelayPin = 7;
const int intermittentRelayPin = 8;
const int earthRelayPin = 9;

// Variables to store input states
int parkState = LOW;
int intermittentState = LOW;
int lowState = LOW;
int highState = LOW;

void setup() {
  // Set input pins
  pinMode(parkPin, INPUT);
  pinMode(intermittentPin, INPUT);
  pinMode(lowPin, INPUT);
  pinMode(highPin, INPUT);

  // Set output pins
  pinMode(lowRelayPin, OUTPUT);
  pinMode(highRelayPin, OUTPUT);
  pinMode(intermittentRelayPin, OUTPUT);
  pinMode(earthRelayPin, OUTPUT);

  // Initialize relay states
  digitalWrite(lowRelayPin, LOW);
  digitalWrite(highRelayPin, LOW);
  digitalWrite(intermittentRelayPin, LOW);
  digitalWrite(earthRelayPin, HIGH);

  // Initialize serial communication
  Serial.begin(9600);
}

void loop() {
  // Read input states
  parkState = digitalRead(parkPin);
  intermittentState = digitalRead(intermittentPin);
  lowState = digitalRead(lowPin);
  highState = digitalRead(highPin);

  // Check conditions and set relay states
  if (parkState == HIGH) {
    digitalWrite(lowRelayPin, HIGH);
    digitalWrite(highRelayPin, HIGH);
    digitalWrite(earthRelayPin, LOW);
    digitalWrite(intermittentRelayPin, LOW);
  } else if (intermittentState == HIGH) {
    digitalWrite(lowRelayPin, HIGH);
    digitalWrite(highRelayPin, HIGH);
    digitalWrite(earthRelayPin, LOW);
    digitalWrite(intermittentRelayPin, HIGH);
  } else if (lowState == HIGH) {
    digitalWrite(lowRelayPin, HIGH);
    digitalWrite(highRelayPin, HIGH);
    digitalWrite(earthRelayPin, HIGH);
    digitalWrite(intermittentRelayPin, LOW);
  } else if (highState == HIGH) {
    digitalWrite(lowRelayPin, LOW);
    digitalWrite(highRelayPin, HIGH);
    digitalWrite(earthRelayPin, HIGH);
    digitalWrite(intermittentRelayPin, LOW);
  } else {
    // Default state: all relays off
    digitalWrite(lowRelayPin, LOW);
    digitalWrite(highRelayPin, LOW);
    digitalWrite(earthRelayPin, LOW);
    digitalWrite(intermittentRelayPin, LOW); }
  // Print input states (for debugging)
  Serial.print("Park: ");
  Serial.print(parkState);
  Serial.print(" Intermittent: ");
  Serial.print(intermittentState);
  Serial.print(" Low: ");
  Serial.print(lowState);
  Serial.print(" High: ");
  Serial.println(highState);

  delay(100);  // Delay for stability
}
