Bonjour la communauté de l'Arduino ! (oui oui je sors )
J'ai acheté un écran LCD Keypad Shield il y a peu. Pour l'essayer, je veux faire deux trois petits trucs un peu inutiles mais qui permettent de tenter de grandes choses par la suite !
Alors tout d'abord voilà ce que je veux faire : augmenter ou diminuer unité par unité le chiffre se trouvant au dessus du curseur avec les boutons UP et DOWN et pouvoir me déplacer sur le chiffre que je veux (en affichant le curseur) avec les boutons LEFT et RIGHT.
Sur la première ligne à partir du premier caractère, j'affiche dès le début 0000. Et ce sont ces chiffres que je peux modifier, mais on choisit toujours le chiffre entre 0 et 9, il n'y a pas de "retenues"
Alors voilà mon programme et juste après je vous met mon PROBLÈME :
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int u = 0 ;
int d = 0 ;
int c = 0 ;
int m = 0 ;
int x = 0 ;// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;// For V1.0 comment the other threshold and use the one below:
/*
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
*/
}void setup()
{
lcd.begin(16, 2); // start the library
//lcd.setCursor(0,0);
//lcd.print("Push the buttons"); // print a simple message
lcd.setCursor(x,0); // move to the begining of the second line
}void loop()
{
// Turn off the cursor:
/lcd.noCursor();/
/delay(500);/lcd.cursor();
delay(200);
lcd.noCursor();
delay(200);lcd.setCursor(3,0); // move cursor to second line "1" and 9 spaces over
lcd.print(u);
lcd.setCursor(2,0); // move cursor to second line "1" and 9 spaces over
lcd.print(d);
lcd.setCursor(1,0); // move cursor to second line "1" and 9 spaces over
lcd.print(c);
lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over
lcd.print(m);lcd.setCursor(x,0);
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
x = x+1;
if(x>3)
x = 0;
lcd.setCursor(x,0);
break;
}
case btnLEFT:
{
x = x-1;
if(x<0)
x = 3;
lcd.setCursor(x,0);
break;
}case btnUP:
{
if(x=0){
m = m + 1;
if(m>9)
m = 0;
lcd.print(m);
break;
}
if(x=1){
c = c + 1;
if(c>9)
c = 0;
lcd.print(c);
break;
}
if(x=2){
d = d + 1;
if(d>9)
d = 0;
lcd.print(d);
break;
}
if(x=3){
u = u + 1;
if(u>9)
u = 0;
lcd.print(u);
break;
}}
case btnDOWN:
{
if(x=0){
m = m - 1;
if(m<0)
m = 9;
lcd.print(m);
break;
}
if(x=1){
c = c - 1;
if(c<0)
c = 9;
lcd.print(c);
break;
}
if(x=2){
d = d - 1;
if(d<0)
d = 9;
lcd.print(d);
break;
}
if(x=3){
u = u - 1;
if(u<0)
u = 9;
lcd.print(u);
break;
}}
case btnSELECT:
{
// lcd.print("SELECT");
break;
}
break;
}}
Alors le fameux problème : peut importe ou je place mon curseur au début, j'incrémente de 1 et le chiffre va se placer avec le curseur au niveau des centaines... Je voudrais qu'il reste là où je lui ai demandé d'être moi...
ILLUSTRATION : 0000 -> 1000 -> 0100 (le trait qui souligne est le curseur, la deuxième étape l’incrémentation et ensuite le résultat final)
Je suis perdu... Quelqu'un peut m'aider ?