#define Pump 0
#define S1State 1
#define S2State 2
#define S3State 3
#define S4State 4

int StartUpPause = 1000*3; //default value: 1000*60 (1 sec * 60 means wait 60 seconds)
int PumpUpTime = 200; //dafault value: 200 ms pulse time for pump
int PumpPauseTime = 1000*3; //default value: 1000*120 (1 sec * 120 means pause for 120 seconds between pulses)
int FillUpTime = 1000*5; //default value: 1000*30 (1 sec * 30 means start pump to fill wires with oil for 30 seconds)
int FillUpPauseTime = 1000*10; //default value 1000 * 30 (1sec * 30 pause pump filling oil for 30 seconds to cool down pump)
unsigned long CurrentTime;
unsigned long LoopEndTime;

// setup function runs once after reset button pressed or powered on
void setup() {
  pinMode(Pump, OUTPUT);
  pinMode(S1State, INPUT_PULLUP); //S1 for onroad low oil S2 * 1.5
  pinMode(S2State, INPUT_PULLUP); //S2 for onroad high oil nomimnal value pump pause of 'PumpPauseTime'
  pinMode(S3State, INPUT_PULLUP); //S3 for offroad (wet) low oil S2 *0.75
  
  digitalWrite(Pump, LOW); //set Pump state as LOW (reset pump)
  delay(StartUpPause); //wait some time on startup
  digitalWrite(Pump, HIGH); //pulse once just to know pump works
  delay(PumpUpTime);
  digitalWrite(Pump, LOW);
}

//loop function runs over and over forever
void loop() {

if (digitalRead (S1State) == LOW && digitalRead (S2State) == HIGH && digitalRead (S3State) == HIGH) {
    //digitalWrite(Pump, LOW);
    CurrentTime = millis();
    if (CurrentTime >= (LoopEndTime + PumpPauseTime *2)) {
      digitalWrite(Pump, HIGH);
    }
    if (CurrentTime >= (LoopEndTime + PumpPauseTime *2 + PumpUpTime)) {
      digitalWrite(Pump, LOW);
      LoopEndTime = CurrentTime;
    }
  }

if (digitalRead (S1State) == LOW && digitalRead (S2State) == LOW && digitalRead (S3State) == HIGH) {
    //digitalWrite(Pump, LOW);
    CurrentTime = millis();
    if (CurrentTime >= (LoopEndTime + PumpPauseTime *2)) {
      digitalWrite(Pump, HIGH);
    }
    if (CurrentTime >= (LoopEndTime + PumpPauseTime *2 + PumpUpTime)) {
      digitalWrite(Pump, LOW);
      LoopEndTime = CurrentTime;
    }
  }

if (digitalRead (S1State) == HIGH && digitalRead (S2State) == LOW && digitalRead (S3State) == HIGH) {
    //digitalWrite(Pump, LOW);
    CurrentTime = millis();
    if (CurrentTime >= LoopEndTime + PumpPauseTime) {
      digitalWrite(Pump, HIGH);
    }
    if (CurrentTime >= LoopEndTime + PumpPauseTime + PumpUpTime) {
      digitalWrite(Pump, LOW);
      LoopEndTime = CurrentTime;
    }
  }

if (digitalRead (S1State) == HIGH && digitalRead (S2State) == LOW && digitalRead (S3State) == LOW) {
    //digitalWrite(Pump, LOW);
    CurrentTime = millis();
    if (CurrentTime >= LoopEndTime + PumpPauseTime * 0.66) {
      digitalWrite(Pump, HIGH);
    }
    if (CurrentTime >= LoopEndTime + PumpPauseTime *0.66 + PumpUpTime) {
      digitalWrite(Pump, LOW);
      LoopEndTime = CurrentTime;
    }
  }

if (digitalRead (S1State) == HIGH && digitalRead (S2State) == HIGH && digitalRead (S3State) == LOW) {
    //digitalWrite(Pump, LOW);
    CurrentTime = millis();
    if (CurrentTime >= LoopEndTime + PumpPauseTime * 0.33) {
      digitalWrite(Pump, HIGH);
    }
    if (CurrentTime >= LoopEndTime + PumpPauseTime *0.33 + PumpUpTime) {
      digitalWrite(Pump, LOW);
      LoopEndTime = CurrentTime;
    }
  }

if (digitalRead (S1State) == LOW && digitalRead (S2State) == LOW && digitalRead (S3State) == LOW) {
    //digitalWrite(Pump, LOW);
    CurrentTime = millis();
    if (CurrentTime >= LoopEndTime + FillUpPauseTime) {
      digitalWrite(Pump, HIGH);
    }
    if (CurrentTime >= LoopEndTime + FillUpPauseTime + FillUpTime) {
      digitalWrite(Pump, LOW);
      LoopEndTime = CurrentTime;
    }
  } 

if (digitalRead (S1State) == HIGH && digitalRead (S2State) == HIGH && digitalRead (S3State) == HIGH) {
      digitalWrite(Pump, LOW);
    }
  
//digitalWrite(Pump,LOW);
}
ATTINY8520PU