1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| void loop()
{
// on teste si le bouton ENTER est pressé --> si oui, on rentre dans le mode de calibration
etatBoutonEnter = digitalRead(pinBoutonEnter);
if (etatBoutonEnter > lastBoutonEnter)
{
testBoutonEnter=1;
ph.calibration(voltage,temperature,"ENTERPH"); // on envoie la commande ENTERPH au module pour commencer la calibration
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("->etalonnage pHmetre");
lcd.setCursor(0, 1);
lcd.print("CAL pour valider");
lcd.setCursor(0, 2);
lcd.print("EXIT pour quitter ");
int i=6;
while (i>=0)
{
lcd.setCursor(0,3);
lcd.print("Attendre ");
lcd.setCursor(9,2);
lcd.print(i);
lcd.setCursor(10,2);
lcd.print(" sec");
delay(1000);
i=i-1;
}
lcd.setCursor(0,2);
lcd.print(" ");
if(lastBoutonCal == LOW) // on teste l'appui sur Cal après avoir appuyé au préalable sur Enter
while (testBoutonEnter == 1)
{ // on teste si le bouton CAL est pressé --> si oui, on valide l'étalonnage
etatBoutonCal = digitalRead(pinBoutonCal);
if (etatBoutonCal)
{
lcd.backlight();
lcd.clear();
ph.calibration(voltage,temperature,"CALPH"); // calibration process by Serail CMD
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("->etalonnage reussi ");
lcd.setCursor(0, 1);
lcd.print("EXIT pour sauvegarde");
lcd.setCursor(0, 2);
lcd.print("et pour quitter ");
testBoutonCal=1;
}
if(lastBoutonExit == LOW) // Appui sur E après appui maintenu sur Enter
while (testBoutonCal == 1) // C'est bien un = et non == ;-)
{
etatBoutonExit = digitalRead(pinBoutonExit);
if (etatBoutonExit)
{
lcd.backlight();
lcd.clear();
ph.calibration(voltage,temperature,"EXITPH"); // calibration process by Serail CMD
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("->Etalonnage reussi ");
delay(1000);
lcd.clear();
testBoutonEnter=0;
testBoutonCal=0;
break;
}
}
}
}
else // "else" salvateur
{
etatBoutonCal = digitalRead(pinBoutonCal);
etatBoutonExit = digitalRead(pinBoutonExit);
if (etatBoutonExit > lastBoutonExit)
{
ph.calibration(voltage,temperature,"EXITPH"); // calibration process by Serail CMD
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("->Etalonnage arrete");
delay(2000);
lcd.clear();
}
}
lastBoutonEnter= etatBoutonEnter;
lastBoutonCal = etatBoutonCal;
lastBoutonExit = etatBoutonExit;
float resultatph=0.0;
static unsigned long timepoint = millis();
if(millis()-timepoint>2000U) //time interval: 2s
{
timepoint = millis();
for (int i =0;i<cycles;i++){
voltage = analogRead(PH_PIN)/1024.0*5000; // read the voltage
//temperature = readTemperature(); // read your temperature sensor to execute temperature compensation
phValue = ph.readPH(voltage,temperature); // convert voltage to pH with temperature compensation
//Serial.print("temperature:");
//Serial.print(temperature,1);
//Serial.print("^C pH:");
resultatph += phValue;
}
resultatph /= cycles;
Serial.println(resultatph,2);
lcd.setCursor(0, 3);
lcd.print("pH = ");
lcd.setCursor(5, 3);
lcd.print(resultatph,2);
}
ph.calibration(voltage,temperature); // calibration process by Serail CMD
delay(50);
} |