//#include <Wire.h> //Importer la library Wire
//#include "rgb_lcd.h" //Importer la library rgb_lcd
//rgb_lcd lcd; //Crée l'ecran
#include <LiquidCrystal_I2C.h> //Importer la library LCD_I2C
LiquidCrystal_I2C lcd(0x27,16,2); //Définir l'adress et la taille de l'ecran
int p1[] = {0, 0};
int p2[] = {0, 0};
float pM[] = {0, 0};
int int_step = 0;
const int colorR = 255;
const int colorG = 255;
const int colorB = 255;
String point_list[] = {"x1", "y1", "x2", "y2"};
void setup() {
Serial.begin(9600);
Serial.println("fdp");
// set up the LCD's number of columns and rows:
//lcd.begin(16, 2); //Définir la taille de l'ecran
//lcd.setRGB(colorR, colorG, colorB); //Définir la couleur de l'ecran
lcd.init(); //Initialiser l'ecran
lcd.backlight(); //Allumer le backlight
}
void loop() {
if (Serial.available()) {
String inputString = ""; // Create an empty string to store the input
while (Serial.available()) {
char inChar = Serial.read();
if (inChar == '\n') { // Check for newline character to indicate end of input
break;
}
inputString += inChar; // Append the character to the string
}
if (inputString.length() > 0) {
if (int_step < 2) {
p1[int_step%2] = inputString.toInt();
}
if (int_step < 4) {
p2[int_step%2] = inputString.toInt();
}
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("OK");
delay(500);
lcd.clear();
int_step++;
if (int_step > 4) {
int_step = 0;
}
}
}
if (int_step < 4) {
lcd.setCursor(0, 0);
String pos = point_list[int_step];
lcd.print(pos);
lcd.print(" ?");
}
if (int_step == 4) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("p1 ");
lcd.print(p1[0]);
lcd.print(",");
lcd.print(p1[1]);
lcd.print(" p2 ");
lcd.print(p2[0]);
lcd.print(",");
lcd.print(p2[1]);
pM[0] = (p1[0]+p2[0])/2.0;
pM[1] = (p1[1]+p2[1])/2.0;
lcd.setCursor(0, 1);
lcd.print("M = (");
lcd.print(pM[0]);
lcd.print(", ");
lcd.print(pM[1]);
lcd.print(")");
delay(500);
lcd.clear();
}
}