Arduino, problème d'affichage et de switch

Screampy57 Messages postés 1 Date d'inscription mardi 14 mars 2017 Statut Membre Dernière intervention 14 mars 2017 - Modifié par cptpingu le 14/03/2017 à 17:48
Dalfab Messages postés 706 Date d'inscription dimanche 7 février 2016 Statut Membre Dernière intervention 2 novembre 2023 - 14 avril 2017 à 14:00
Bonjour, je suis étudiant en BTS SN et pour mon projet je dois réaliser un didacticiel à partir d'un Arduino Mega 2560, de 3 boutons poussoir et d'un afficheur graphique TFT2.8".

J'ai déjà réalisé le code sauf que mes messages (mes println) se superposent sur l'écran et mes boutons ne font pas changer mes pages.

Je vous mets le code afin que vous compreniez plus en détail ma demande:
//#define DEBUG
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library


#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin



// Couleurs d'écriture et de fond possible
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

#define initial 0
#define client 1
#define page11 2
#define page12 3
#define page13 4
#define page14 5
#define page21 6
#define page22 7
#define page23 8
#define page24 9
#define technicien 10
#define page31 11
#define page32 12
#define page33 13
#define page34 14
#define page41 15
#define page42 16
#define page43 17
#define page44 18

const int boutonp = 35 ;
const int boutonm = 37 ;
const int boutonok = 39 ;

int etat=0;

unsigned long envoiMessage(char*texte);

#define DEBUG 1
void setup(void) {
 #ifdef DEBUG
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));
  Serial.print("TFT size is ");
  Serial.print(tft.width());
  Serial.print("x");
  Serial.println(tft.height());
#endif // DEBUG
  tft.reset();

pinMode(boutonp, INPUT);
pinMode(boutonm, INPUT);
pinMode(boutonok, INPUT);

#ifdef DEBUG
  uint16_t identifier = tft.readID();

  switch (identifier)
  {
    case 0x9325:    Serial.println(F("Found ILI9325 LCD driver")); break;

    case 0x9328:    Serial.println(F("Found ILI9328 LCD driver")); break;

    case 0x7575:    Serial.println(F("Found HX8347G LCD driver")); break;

    case 0x9341:    Serial.println(F("Found ILI9341 LCD driver")); break;

    case 0x8357:    Serial.println(F("Found HX8357D LCD driver")); break;

    default    :    Serial.print(F("Unknown LCD driver chip: "));


                      Serial.println(identifier, HEX);
                      Serial.print(F("I try use ILI9341 LCD driver "));
                      Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
                      Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
                      Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
                      Serial.println(F("If using the breakout board, it should NOT be #defined!"));
                      Serial.println(F("Also if using the breakout, double-check that all wiring"));
                      Serial.println(F("matches the tutorial."));
#endif // DEBUG
    identifier = 0x9341;
    break;
  } // fin switch





                      tft.begin(identifier);
                      tft.setRotation(3);
                      tft.setTextColor(WHITE);
                      tft.setTextSize(3);
                      tft.fillScreen(BLACK);


#ifdef DEBUG


                     Serial.print(F("Fin Setup                     "));



#endif // DEBUG


}//fin setup


void loop(void) 

 {
   switch(etat)
   {
        case initial:
         tft.println("Initial");
        if (boutonp) etat=client;
        if (boutonm) etat=technicien;
        break;

        case client:
         tft.println("Client");
        if (boutonp) etat=page11;
        if (boutonm) etat=page21;
        if (boutonok) etat=initial;
        break;

        case technicien:
         tft.println("technicien");
        if (boutonp) etat=page31;
        if (boutonm) etat=page41;
        if (boutonok) etat=initial;
        break;

        case page11:
        tft.println("11");
        if (boutonp) etat=page12;
        if (boutonm) etat=client;
        if (boutonok) etat=initial;
        break;

        case page12:
        tft.println("12");
        if (boutonp) etat=page13;
        if (boutonm) etat=page11;
        if (boutonok) etat=initial;
        break;

         case page13:
         tft.println("13");
        if (boutonp) etat=page14;
        if (boutonm) etat=page12;
        if (boutonok) etat=initial;
        break;

         case page14:
         tft.println("14");
        if (boutonp) etat=initial;
        if (boutonm) etat=page13;
        if (boutonok) etat=initial;
        break;

         case page21:
         tft.println("21");
        if (boutonp) etat=page22;
        if (boutonm) etat=client;
        if (boutonok) etat=initial;
        break;

         case page22:
         tft.println("22");
        if (boutonp) etat=page23;
        if (boutonm) etat=page21;
        if (boutonok) etat=initial;
        break;

         case page23:
         tft.println("23");
        if (boutonp) etat=page24;
        if (boutonm) etat=page22;
        if (boutonok) etat=initial;
        break;

         case page24:
         tft.println("24");
        if (boutonp) etat=initial;
        if (boutonm) etat=page23;
        if (boutonok) etat=initial;
        break;

        case page31:
         tft.println("31");
        if (boutonp) etat=page32;
        if (boutonm) etat=technicien;
        if (boutonok) etat=initial;
        break;

         case page32:
         tft.println("32");
        if (boutonp) etat=page33;
        if (boutonm) etat=page31;
        if (boutonok) etat=initial;
        break;

         case page33:
         tft.println("33");
        if (boutonp) etat=page34;
        if (boutonm) etat=page32;
        if (boutonok) etat=initial;
        break;

         case page34:
         tft.println("34");
        if (boutonp) etat=initial;
        if (boutonm) etat=page33;
        if (boutonok) etat=initial;
        break;

         case page41:
         tft.println("41");
        if (boutonp) etat=page42;
        if (boutonm) etat=technicien;
        if (boutonok) etat=initial;
        break;

         case page42:
         tft.println("42");
        if (boutonp) etat=page43;
        if (boutonm) etat=page41;
        if (boutonok) etat=initial;
        break;

         case page43:
         tft.println("43");
        if (boutonp) etat=page44;
        if (boutonm) etat=page42;
        if (boutonok) etat=initial;
        break;

         case page44:
         tft.println("44");
        if (boutonp) etat=initial;
        if (boutonm) etat=page43;
        if (boutonok) etat=initial;
        break;

        default:
        tft.println ("Erreur");
      break;
    }
tft.setCursor(0, 0);
}//fin loop


unsigned long envoiMessage(char*texte) 
{

  unsigned long start = micros();


  tft.println(texte);

  return micros() - start;
}//fin envoimessage


Si vous avez des solutions à m'apporter ou des questions plus précise, ça serait sympa.

Merci à bientôt.
Screampy57

2 réponses

Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
28 mars 2017 à 14:22
Salut,

Je n'ai pas regardé le code en détail mais 2 choses peuvent être la cause:
1 - Tu places systématiquement le curseur en 0, 0, ce qui n'est pas gênant en soit, mais, vue qu'il y a le 2ieme point...
2 - Je ne vois pas, dans le code que tu as donné, d'effacement de l'écran...

Autre petite chose, dans ta fonction 'loop' tu peux remplacer les 'if' par des 'if' 'else if' (pour la gestion de la variable 'etat').

0
Dalfab Messages postés 706 Date d'inscription dimanche 7 février 2016 Statut Membre Dernière intervention 2 novembre 2023 11
14 avril 2017 à 14:00
Bonjour,

tu dis "mes messages (mes println) se superposent sur l'écran". Le code dit explicitement après avoir écris quelque chose, revenir à la première ligne. Si ça n'est pas ce que tu veux, ne le fait pas!
tu dis "mes boutons ne font pas changer mes pages". Là se posent deux questions :
- Qu'est-ce qu'une page dans ton idée?
- Sais-tu comment sont vus les états possibles d'un bouton par un code. Tu dois avoir un cours sur les E/S TOR. Que crois-tu tester en faisant if ( boutonp )
- - Le bouton plus a été cliqué dernièrement?
- - Le bouton plus est appuyé à l'instant précis d'exécution du code?
- - Le bouton plus est cliqué à cet instant?
- - Autre chose ?
Je n'ai pas la réponse, elle dépend de la connexion des boutons (et sauf qu'une des propositions est idiote).
0
Rejoignez-nous