/**
* Code de base pour l'utilisation de la shield Arduino LCD de DFRobots (LCD uniquement).
*/
/* Dépendances */
#include <LiquidCrystal.h>
/* variable */
int bouton;
int Pot; // variable to store the value coming from the analog pin
int data0;
int x;
int iMax;
/** Broche pour le contrôle du rétroéclairage */
const byte BACKLIGHT_PWM_PIN = 10;
/** Objet LiquidCrystal pour communication avec l'écran LCD */
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
unsigned long tepTimer ;
/** Fonction setup() */
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 1);
lcd.print("Pre Select to 0mm");
bouton = 0;
data0 = 0;
iMax = 540;
}
/** Fonction loop() */
void loop() {
lcd.setCursor(0, 0); // set the LCD cursor position
x=analogRead(0);
double data; // variable to store the potentiometre value coming from the conversion formula
Pot=analogRead(1); // read the analog in value:
data = (double) Pot * 0.527; // formule conversion koHm = mm
if(x < 800){
lcd.setCursor(0, 1);
lcd.print ("zero effectue ");
iMax = data;
}
data0 = (iMax - data) * 0.95;
if(millis() - tepTimer > 200){ // output a potentiometre value per 200ms
tepTimer = millis();
// print the results to the lcd
lcd.setCursor(0, 0);
lcd.print("Profond: ");
lcd.print(data0);
lcd.print(" dmm ");
}
}