#include <LiquidCrystal_I2C.h> // Importer la librairie LCD_I2C
LiquidCrystal_I2C lcd(0x27, 16, 2); // Définir l'adresse et la taille de l'écran
int point_1[] = {0, 0};
int point_2[] = {0, 0};
float point_moyenne[] = {0, 0};
int step = 0; // Compteur pour suivre l'état d'entrée
int inputIndex = 0; // Indice pour identifier quelle coordonnée est entrée
void setup() {
Serial.begin(9600);
lcd.init(); // Initialiser l'écran
lcd.backlight(); // Activer le rétroéclairage
Serial.print(" ");
}
void loop() {
// Vérification des entrées série
if (Serial.available()) {
String inputString = ""; // Créer une chaîne vide pour stocker l'entrée
while (Serial.available()) {
char inChar = Serial.read();
if (inChar == '\n') { // Vérifier la fin de l'entrée
break;
}
inputString += inChar; // Ajouter chaque caractère à la chaîne
}
if (inputString.length() > 0) {
int inputValue = inputString.toInt(); // Convertir l'entrée en entier
if (step == 0) { // Entrer x1
point_1[0] = inputValue;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("x1: ");
lcd.print(point_1[0]);
step++; // Passer à l'étape suivante
}
else if (step == 1) { // Entrer y1
point_1[1] = inputValue;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("y1: ");
lcd.print(point_1[1]);
step++;
}
else if (step == 2) { // Entrer x2
point_2[0] = inputValue;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("x2: ");
lcd.print(point_2[0]);
step++;
}
else if (step == 3) { // Entrer y2
point_2[1] = inputValue;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("y2: ");
lcd.print(point_2[1]);
step++;
}
}
}
// Affichage une fois que toutes les coordonnées sont entrées
if (step == 4) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("p1(");
lcd.print(point_1[0]); // x1
lcd.print(",");
lcd.print(point_1[1]); // y1
//lcd.setCursor(0, 1);
lcd.print(") p2(");
lcd.print(point_2[0]); // x2
lcd.print(",");
lcd.print(point_2[1]); // y2
lcd.print(")");
// Calcul du point milieu
point_moyenne[0] = (point_1[0] + point_2[0]) / 2.0;
point_moyenne[1] = (point_1[1] + point_2[1]) / 2.0;
delay(1000); // Attente pour l'affichage
//lcd.clear();
lcd.setCursor(0, 1);
lcd.print("pM(");
lcd.print(point_moyenne[0]); // x3
lcd.print(", ");
lcd.print(point_moyenne[1]); // y3
lcd.print(")");
delay(20000); // Pause avant de réinitialiser
lcd.clear();
step = 0; // Réinitialisation pour un nouvel ensemble de points
}
}