// LCD Keypad Shield
#include <LiquidCrystal.h>
// Création de l'objet lcd (avec les différents ports numériques qu'il utilise)
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// Variables
int lcd_key = 0;
int adc_key_in = 0;
// Constantes
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
lcd.begin(16, 2); // Démarrage de l'écran
lcd.setCursor(0,0); // Positionnement du curseur au début
lcd.print("59jag"); // Message
lcd.setCursor(0,1);
lcd.print("reset");
delay(500);
}
void loop()
{
lcd.setCursor(0,1); // Positionnement du curseur début de ligne 1
lcd_key = read_LCD_buttons(); // Lecture des touches
switch (lcd_key) // Action en cas de touche pressée
{
case btnRIGHT:
{
lcd.print("DROITE");
break;
}
case btnLEFT:
{
lcd.print("GAUCHE");
break;
}
case btnUP:
{
lcd.print("HAUT ");
break;
}
case btnDOWN:
{
lcd.print("BAS ");
break;
}
case btnSELECT:
{
lcd.print("SELECT");
break;
}
case btnNONE:
{
lcd.print(" ");
break;
}
}
}
// Fonction de lecture des touches
int read_LCD_buttons()
{
adc_key_in = analogRead(A0); // Lecture du port analogique
Serial.println(adc_key_in);
if (adc_key_in < 50) return btnRIGHT; // 0
if (adc_key_in < 195) return btnUP; // 99
if (adc_key_in < 380) return btnDOWN; // 255
if (adc_key_in < 555) return btnLEFT; // 409
if (adc_key_in < 790) return btnSELECT; // 640
return btnNONE;
}