#define VCC 5 //spanning van de arduino (kan ook 3.3 V zijn)
#define TIME_ON 1000 // tijd in milliseconden waarin de relais aan moet staan
#define TIME_OFF 10000 // tijd in milliseconden waarin de relais uit moet staan

#define RELAY_PIN 12
#define DISCHARGE_PIN 13

void setup() {
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(DISCHARGE_PIN, OUTPUT);
  Serial.begin(115200);
}

unsigned long oldmillis = 0;

void loop() {
  unsigned long currentmillis = millis();
  double a0 = map(analogRead(A0), 0, 1023, 0, VCC * 100) / 100.0;
  double a1 = map(analogRead(A1), 0, 1023, 0, VCC * 100) / 100.0;
  double voltage = a1 - a0;

  if (voltage <= 1.0) {
    digitalWrite(DISCHARGE_PIN, HIGH);
  } else {
    digitalWrite(DISCHARGE_PIN, LOW);
  }

  if (currentmillis - oldmillis >= TIME_OFF + TIME_ON) {
    digitalWrite(RELAY_PIN, LOW);
    oldmillis = currentmillis;
  } else if (currentmillis - oldmillis >= TIME_OFF) {
    digitalWrite(RELAY_PIN, HIGH);
  }

  Serial.print("A0: ");
  Serial.print(a0);
  Serial.print("  A1: ");
  Serial.print(a1);
  Serial.print("\tV:");
  Serial.print(voltage);
  Serial.print("\n");
}