#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

char auth[] = "hneeH3NrG9r-e1jrrECsZiB_-TUkU6z7"; //220L

char ssid[] = "Livebox-7C2C";
char pass[] = "566C61F61F9C925C9F3D7D79E6";

WidgetRTC rtc;
BlynkTimer timer;
WidgetTerminal terminal(V60);

//************************************************************************
//                Variable Global perso
//************************************************************************

const int Arriver = 5;
const int Evacuation = 4;
const int PompeOsmo = 16;
const int PompeRemo = 14;
const int NiveauHau = 12;
const int Pistolet = 13;


const int NiveauBas = 9;
const int Autre = 10;

  
//************************************************************************
//                Fonction Seul
//************************************************************************
void Demarre(){
  digitalWrite(Arriver, HIGH);
  digitalWrite(Evacuation, HIGH);
  delay(10000); //mise en eau du circuit
  digitalWrite(PompeOsmo, HIGH);
  delay(60000); //Rincage 1min
  digitalWrite(Evacuation, LOW);
}

void Stop(){
  digitalWrite(PompeOsmo, LOW);
  delay(10000); //mise en eau du circuit
  digitalWrite(Arriver, LOW);
}

void setup(){

  //Pin Setup
  pinMode(Arriver, OUTPUT);
  pinMode(Evacuation, OUTPUT);
  pinMode(PompeOsmo, OUTPUT);
  pinMode(PompeRemo, OUTPUT);
  pinMode(NiveauHau, INPUT);
  pinMode(Pistolet, INPUT);
  pinMode(NiveauBas, INPUT);
  
  digitalWrite(Arriver, LOW);
  digitalWrite(Evacuation, LOW);
  digitalWrite(PompeOsmo, LOW);
  digitalWrite(PompeRemo, LOW);
}

void loop(){
  if(NiveauHau==0)
    Demarre();
  else
    Stop();
}