merci de ton intervention dfgh,
jái remis le key a sa place, effetivement j'avais besoin de la variable pour la suite du code. merci de cette confirmation. pour la UNO je nái pas indique que les valeurs de analogRead sont differentes car les boutons sont greffes sur le shied lcd/buttons :
// read the buttons
unsigned char read_LCD_buttons() {// lecture des boutons du menu principal
key = analogRead(A0); // read the value from the sensor
if (key > 1000) return btnNONE;
if (key < 50) return btnRIGHT;
if (key < 195) return btnUP;
if (key < 380) return btnDOWN;
if (key < 555) return btnLEFT;
if (key < 790) return btnSELECT;
return btnNONE;
delay(100);
les pins sont connectes comme suit :
// config pour arduino UNO + shield
//LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
cette config fonctionne sans probleme. j'ai juste deporte les boutons et le LCD.
voici le code complet :
#include <LiquidCrystal.h>
#include "Menu.h" // Fichier d'entête avec les types pour le menu
#include <Servo.h>
#include "Arduino.h"
#include <SoftwareSerial.h>
// config pour arduino UNO
//LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // avec la UNO et shield lcd + boutons : tout fonctionne normalement
//OU config pour NANO
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// valeurs des boutons
unsigned char key = 0;// var resultat de lecture des boutons
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2); // init LCD library
}
unsigned char read_LCD_buttons()
{
key = analogRead(A0); //lecture de la valeur
if (key > 1000) return btnNONE;
if (key < 50) return btnRIGHT;
if (key < 195) return btnUP;
if (key < 380) return btnDOWN;
if (key < 555) return btnLEFT;
if (key < 790) return btnSELECT;
return btnNONE;
}
void avance(){
lcd.clear();
lcd.setCursor(2,1);
lcd.print("o>>");
}
void recule(){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("<<o");
}
void arret(){
lcd.clear();
lcd.setCursor(0,1);
lcd.print(" <o> ");
}
void loop(){
key = read_LCD_buttons(); // read the buttons
if(key == btnLEFT){recule();}
if(key == btnRIGHT){avance();}
if(key == btnSELECT){lcd.print("menu");}
if(key == btnNONE){arret();}
Serial.print("sensor = " );
Serial.println(analogRead(0)); // affichage sur le serial
delay(2);
}
Maintenant j'ai cette erreur a la compile :
In file included from sketch_aug05a.ino:4:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:117:14: error: conflicting declaration 'typedef bool boolean'
typedef bool boolean;
^
In file included from C:\Users\..\Desktop\Arduino\libraries\Menu/WProgram.h:10:0,
from C:\Users\..\Desktop\Arduino\libraries\Menu/Menu.h:33,
from sketch_aug05a.ino:2:
C:\Users\..\Desktop\Arduino\libraries\Menu/wiring.h:97:17: error: 'boolean' has a previous declaration as 'typedef uint8_t boolean'
typedef uint8_t boolean;
^
In file included from sketch_aug05a.ino:4:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:235:83: error: default argument given for parameter 3 of 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)' [-fpermissive]
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
^
In file included from sketch_aug05a.ino:4:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:136:15: error: after previous specification in 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)' [-fpermissive]
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
^
In file included from sketch_aug05a.ino:4:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:238:75: error: default argument given for parameter 3 of 'void tone(uint8_t, unsigned int, long unsigned int)' [-fpermissive]
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
^
In file included from C:\Users\guy\Desktop\Arduino\libraries\Menu/Menu.h:33:0,
from sketch_aug05a.ino:2:
C:\Users\guy\Desktop\Arduino\libraries\Menu/WProgram.h:22:6: error: after previous specification in 'void tone(uint8_t, unsigned int, long unsigned int)' [-fpermissive]
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
^
Erreur lors de la compilation.
Je ne comprends plus rien. Please help.