Announcement

Collapse
No announcement yet.

bugs in simple display code (newbie problem!)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • oumyth
    commented on 's reply
    Hello Paul,

    Thank you so muchl !! I don't have the screen with me anymore but I'll try this within two weeks and will keep you updated.

    Thank you so much for your help !!

    Best regard,
    Oumy

  • pauleilio
    replied
    Hi Oumy

    Can you please try this for me

    change nom to a string

    //char *nom;
    String nom;

    and use this code instead for the function that is failing

    Code:
    void affichage(void) {
    Display.gfx_BGcolour(LIGHTGOLD) ;
    Display.gfx_Cls() ;
    Display.txt_BGcolour(LIGHTGOLD) ;
    Display.txt_FGcolour(BLACK) ;
    Display.print("                                                                                                 ");
    Display.print("Bonjour"); //This is where it gets too slow. I only get this displays like 2 minutes after passing the card in front of the reader. Everything afterwards goes at correct speed.
    Display.print(" ");
    Display.print(nom);
    //Display.putstr(nom);
    Display.print(".");
    Display.print(" ");
    Display.print("Quel est le numero du casier que vous souhaitez emprunter ?") ;
    Display.gfx_BevelShadow(3) ; // make it really dark
    Display.gfx_BevelWidth(20) ; // make the button bigger by increasing the bevel size for (i = 1; i <= 10; i++) { Display.gfx_Button(ON, 120,50, BLUE, WHITE, FONT3, 1, 1, "Smile") ;
    delay(100) ;
    Display.gfx_Button(OFF, 120,200, BLUE, WHITE, FONT3, 1, 1, "1") ;
    delay(100);
    Display.gfx_Button(OFF, 500, 200, BLUE, WHITE, FONT3, 1, 1, "2") ;
    delay(100) ;
    Display.touch_Set(TOUCH_ENABLE);
    }

    Leave a comment:


  • oumyth
    commented on 's reply
    Thank you very much !!

  • pauleilio
    replied
    Ok,

    I'll set this up again and try to find it it, please bear with me a short while.

    Leave a comment:


  • oumyth
    commented on 's reply
    Hello Paul, thank you for the tip ! I'll remember to use gfx_MoveTo to position the text

    I have commented out the lines with a lot of spaces, however the function "affichage" still takes too much time to execute but everything else is at correct speed. I don't kno what I'm missing !

    Best regards,
    Oumy
    Last edited by oumyth; 15 June 2020, 11:33 PM.

  • pauleilio
    replied
    Hi Oumy

    Could you please try commenting out the lines with a lot of spaces eg,

    Display.putstr(" ");

    If they are being used to position text then you could use gfx_MoveTo(xPosition, yPosition); instead of all the spaces

    Best regards

    Paul

    Leave a comment:


  • oumyth
    commented on 's reply
    However, when I use the following code by moving up the function "hello", everything goes at correct speed but nothing happens when I touch the buttons.
    Here's the code :

    Code:
    //Screen
    #define DisplaySerial Serial3                
    #include "Diablo_Serial_4DLib.h"      
    #include "Diablo_Const4D.h"
    #define RESETLINE 4
    
    //Touch
    int x ;
    int y;
    int touch;
    int buttonPressed ;
    int tcount;
    int serrure = 11;
    int ventilo = 12;
    
    //Reader
    #define MAX_BITS 100                 // max number of bits
    #define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse. 
    unsigned char databits[MAX_BITS];    // stores all of the data bits
    unsigned char bitCount;              // number of bits currently captured
    unsigned char flagDone;                       // goes low when data is currently being captured
    unsigned int weigand_counter;        // countdown until we assume there are no more bits
    unsigned long cardCode=0;            // decoded card code 
    unsigned char i;
    
    
    // Screen
    char *nom;
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    //Reader functions
    void ISR_INT0() {
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME; 
      }
    
    
    void ISR_INT1() {
      databits[bitCount] = 1;
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME; 
      }
    
    
    void setup () {
        DisplaySerial.begin(9600);
        pinMode (serrure, OUTPUT);
        pinMode (ventilo, OUTPUT);
        pinMode(RESETLINE, OUTPUT);
        digitalWrite(RESETLINE, HIGH);
        delay(200);
        digitalWrite(RESETLINE, LOW);
        delay(3500);
        Display.TimeLimit4D=2000;
        Display.gfx_ScreenMode(LANDSCAPE);
        Display.putstr("Initialisation en cours");
        delay(500);
        pinMode(2, INPUT_PULLUP);      // DATA0 (INT0)
        pinMode(3, INPUT_PULLUP);      // DATA1 (INT1)
        Serial.begin(9600);
        attachInterrupt(0, ISR_INT0, FALLING); 
        attachInterrupt(1, ISR_INT1, FALLING);
        weigand_counter = WEIGAND_WAIT_TIME;
        delay(5000);
        intro (); 
        }
    
    void intro(void) {
      Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
      Display.gfx_Cls() ;
      Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
      Display.txt_FGcolour(BLACK) ;
      Display.putstr("                                                                                                                        ");
      Display.putstr("Bonjour. Veuillez passez votre badge devant votre lecteur") ; //This is where I ask to pass the card in front of the reader. Everything works until here !
      Display.txt_FGcolour(LIME) ; // reset 
      }
    
    
    void loop() {
      if (!flagDone) {
        if (--weigand_counter == 0)
          flagDone = 1;
          }
    
     if (bitCount > 0 && flagDone) {
        unsigned char i;   
        if (bitCount == 32) {
            for (i=2; i<31; i++) {
               cardCode <<=1;
               cardCode |= databits[i];
               }
              conditions();
              affichage();
              }
              hello();
         bitCount = 0;   // Resets the reader
         cardCode = 0;
         for (i=0; i<MAX_BITS; i++) {
           databits[i] = 0; 
           }
           }
     //  hello();
           }
    
    void conditions()
    {
         if (cardCode == 26741719) {
           nom = "Oumy";
           }
    
          else if ( cardCode == 26759498) {
           nom = "Francois";
           }
    }
    
    
    void affichage(void) {
        Display.gfx_BGcolour(LIGHTGOLD) ; 
        Display.gfx_Cls() ;
        Display.txt_BGcolour(LIGHTGOLD) ;
        Display.txt_FGcolour(BLACK) ;
        Display.putstr("                                                                                                                        ");
        Display.putstr("Bonjour"); //This is where it  gets too slow. I only get this displays like 2 minutes after passing the card in front of the reader. Everything afterwards goes at correct speed.
        Display.putstr (" ");
        Display.putstr(nom);
        Display.putstr(".");
        Display.putstr(" ");
        Display.putstr("Quel est le numero du casier que vous souhaitez emprunter ?") ;
        Display.gfx_BevelShadow(3) ; // make it really dark
        Display.gfx_BevelWidth(20) ; // make the button bigger by increasing the bevel size for (i = 1; i <= 10; i++) { Display.gfx_Button(ON, 120,50, BLUE, WHITE, FONT3, 1, 1, "Smile") ;
        delay(100) ;
        Display.gfx_Button(OFF, 120,200, BLUE, WHITE, FONT3, 1, 1, "1") ;
        delay(100);
        Display.gfx_Button(OFF, 500, 200, BLUE, WHITE, FONT3, 1, 1, "2") ;
        delay(100) ;
        Display.touch_Set(TOUCH_ENABLE);
        }
    
    
    void hello(void) {
        Serial.println(tcount);
        tcount ++;
        touch = Display.touch_Get(TOUCH_STATUS);
        Display.gfx_MoveTo(0,0);
        Display.print(touch);
        if(touch == TOUCH_PRESSED)
        {
         x = Display.touch_Get(TOUCH_GETX);
         y = Display.touch_Get(TOUCH_GETY);
        if ( x > 120 && x < 254 && y > 200 && y < 260 ) // first buttons' coordinates
        {
          digitalWrite(serrure, HIGH) ; 
         Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
         Display.gfx_Cls() ;
         Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
         Display.txt_FGcolour(BLACK) ;
         Display.putstr("                                                                                                                        ");
         Display.putstr("Le casier numero 1 est maintenant deverrouille");
         buttonPressed = 1;
         digitalWrite(serrure, LOW);
         delay(500);
        }
       else if ( x > 500 && x < 632 && y > 200 && y < 260 ) //second buttons' coordinates
       {
        digitalWrite(ventilo, HIGH);
       Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
       Display.gfx_Cls() ;
       Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
       Display.txt_FGcolour(BLACK) ;
       Display.putstr("                                                                                                                        ");
       Display.putstr("Le casier numero 2 est maintenant deverrouille") ;
       buttonPressed = 2;
       digitalWrite(ventilo, LOW);
         delay(500);
       }
       delay(3000);
       Display.gfx_BGcolour(LIGHTGOLD) ; // réinitialize the screen
       Display.gfx_Cls() ;
       Display.txt_BGcolour(LIGHTGOLD) ; 
       Display.txt_FGcolour(BLACK) ;
       Display.putstr("                                                                                                                        ");
       Display.putstr("Bonjour. Veuillez passez votre badge devant votre lecteur") ;
       Display.txt_FGcolour(LIME) ; 
       }
        }

  • oumyth
    commented on 's reply
    Hello Paul,

    I have tried shortening the code for it to be faster. However, the function "affichage" still takes too much time to execute (approx 2 minutes), everything before it and after it goes at correct speed ! I don't know how I could manage to make it faster.

    Here's the code :

    Code:
     
    //Screen
    #define DisplaySerial Serial3                
    #include "Diablo_Serial_4DLib.h"      
    #include "Diablo_Const4D.h"
    #define RESETLINE 4
    
    //Touch
    int x ;
    int y;
    int touch;
    int buttonPressed ;
    int tcount;
    int serrure = 11;
    int ventilo = 12;
    
    //Reader
    #define MAX_BITS 100                 // max number of bits
    #define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse. 
    unsigned char databits[MAX_BITS];    // stores all of the data bits
    unsigned char bitCount;              // number of bits currently captured
    unsigned char flagDone;                       // goes low when data is currently being captured
    unsigned int weigand_counter;        // countdown until we assume there are no more bits
    unsigned long cardCode=0;            // decoded card code 
    unsigned char i;
    
    
    // Screen
    char *nom;
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    //Reader functions
    void ISR_INT0() {
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME; 
      }
    
    
    void ISR_INT1() {
      databits[bitCount] = 1;
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME; 
      }
    
    
    void setup () {
        DisplaySerial.begin(9600);
        pinMode (serrure, OUTPUT);
        pinMode (ventilo, OUTPUT);
        pinMode(RESETLINE, OUTPUT);
        digitalWrite(RESETLINE, HIGH);
        delay(200);
        digitalWrite(RESETLINE, LOW);
        delay(3500);
        Display.TimeLimit4D=2000;
        Display.gfx_ScreenMode(LANDSCAPE);
        Display.putstr("Initialisation en cours");
        delay(500);
        pinMode(2, INPUT_PULLUP);      // DATA0 (INT0)
        pinMode(3, INPUT_PULLUP);      // DATA1 (INT1)
        Serial.begin(9600);
        attachInterrupt(0, ISR_INT0, FALLING); 
        attachInterrupt(1, ISR_INT1, FALLING);
        weigand_counter = WEIGAND_WAIT_TIME;
        delay(5000);
        intro (); 
        }
    
    void intro(void) {
      Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
      Display.gfx_Cls() ;
      Display.txt_BGcolour(LIGHTGOLD) ; // I can't remove it, otherwide the text's background would be black and the writing would look odd ! 
      Display.txt_FGcolour(BLACK) ;
      Display.putstr("                                                                                                                        ");
      Display.putstr("Bonjour. Veuillez passez votre badge devant votre lecteur") ; //This is where I ask to pass the card in front of the reader. Everything works until here !
      Display.txt_FGcolour(LIME) ; // reset 
      }
    
    
    void loop() {
      if (!flagDone) {
        if (--weigand_counter == 0)
          flagDone = 1;
          }
    
     if (bitCount > 0 && flagDone) {
        unsigned char i;   
        if (bitCount == 32) {
            for (i=2; i<31; i++) {
               cardCode <<=1;
               cardCode |= databits[i];
               }
              conditions();
              affichage();  // Takes too much time to execute (approx 2 minutes). Everything before and after this is at correct speed.
    
              }
         bitCount = 0;   // Resets the reader
         cardCode = 0;
         for (i=0; i<MAX_BITS; i++) {
           databits[i] = 0; 
           }
           }
       hello();      
           }
    
    void conditions()
    {
         if (cardCode == 26741719) {
           nom = "Oumy";
           }
    
          else if ( cardCode == 26759498) {
           nom = "Francois";
           }
    }
    
    
    void affichage(void) {
        Display.gfx_BGcolour(LIGHTGOLD) ; 
        Display.gfx_Cls() ;
        Display.txt_BGcolour(LIGHTGOLD) ;
        Display.txt_FGcolour(BLACK) ;
        Display.putstr("                                                                                                                        ");
        Display.putstr("Bonjour"); //This is where it  gets too slow. I only get this displays like 2 minutes after passing the card in front of the reader. Everything afterwards goes at correct speed.
        Display.putstr (" ");
        Display.putstr(nom);
        Display.putstr(".");
        Display.putstr(" ");
        Display.putstr("Quel est le numero du casier que vous souhaitez emprunter ?") ;
        Display.gfx_BevelShadow(3) ; // make it really dark
        Display.gfx_BevelWidth(20) ; // make the button bigger by increasing the bevel size for (i = 1; i <= 10; i++) { Display.gfx_Button(ON, 120,50, BLUE, WHITE, FONT3, 1, 1, "Smile") ;
        delay(100) ;
        Display.gfx_Button(OFF, 120,200, BLUE, WHITE, FONT3, 1, 1, "1") ;
        delay(100);
        Display.gfx_Button(OFF, 500, 200, BLUE, WHITE, FONT3, 1, 1, "2") ;
        delay(100) ;
        Display.touch_Set(TOUCH_ENABLE);
        }
    
    
    void hello(void) {
        Serial.println(tcount);
        tcount ++;
        touch = Display.touch_Get(TOUCH_STATUS);
        Display.gfx_MoveTo(0,0);
        Display.print(touch);
        if(touch == TOUCH_PRESSED)
        {
         x = Display.touch_Get(TOUCH_GETX);
         y = Display.touch_Get(TOUCH_GETY);
        if ( x > 120 && x < 254 && y > 200 && y < 260 ) // first buttons' coordinates
        {
          digitalWrite(serrure, HIGH) ; 
         Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
         Display.gfx_Cls() ;
         Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
         Display.txt_FGcolour(BLACK) ;
         Display.putstr("                                                                                                                        ");
         Display.putstr("Le casier numero 1 est maintenant deverrouille");
         buttonPressed = 1;
         digitalWrite(serrure, LOW);
         delay(500);
        }
       else if ( x > 500 && x < 632 && y > 200 && y < 260 ) //second buttons' coordinates
       {
        digitalWrite(ventilo, HIGH);
       Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
       Display.gfx_Cls() ;
       Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
       Display.txt_FGcolour(BLACK) ;
       Display.putstr("                                                                                                                        ");
       Display.putstr("Le casier numero 2 est maintenant deverrouille") ;
       buttonPressed = 2;
       digitalWrite(ventilo, LOW);
         delay(500);
       }
       delay(3000);
       Display.gfx_BGcolour(LIGHTGOLD) ; // réinitialize the screen
       Display.gfx_Cls() ;
       Display.txt_BGcolour(LIGHTGOLD) ; 
       Display.txt_FGcolour(BLACK) ;
       Display.putstr("                                                                                                                        ");
       Display.putstr("Bonjour. Veuillez passez votre badge devant votre lecteur") ;
       Display.txt_FGcolour(LIME) ; 
       }
        }
    Best regards,
    Oumy

  • pauleilio
    replied
    Hi Oumy,

    There is quite a bit of repetitive code that in some cases only need to be called once or not used and will help overall speed by not sending eg,

    Display.touch_Set(TOUCH_ENABLE);

    This needs to be used only once and just in your setup routine.

    Display.touch_DetectRegion(0, 0, 800, 480);

    Isn't really needed and can be removed.

    Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
    Display.gfx_Cls() ;
    Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd

    You could also remove the 2nd Display.txt_BGcolour(LIGHTGOLD) ; as the BG colour will be set and remain the same after a Display.gfx_Cls() ;

    Best regards

    Paul

    Leave a comment:


  • oumyth
    commented on 's reply
    Hello Paul,

    Thank you so much !

    Best regards,
    Oumy

  • pauleilio
    replied
    Hi Oumy,

    Glad this worked out.

    I will test the code that is slow to respond. I already tested the command in Serial Commader and it works fine so it isn't length related.

    Best regards

    Paul

    Leave a comment:


  • oumyth
    commented on 's reply
    PS : I have another code where once I pass the card in front of the reader, the screen displays at correct speed the two buttons in the function void affichage. However, in the big code I sent 3 minutes ago, it's too slow. Here's the code where it reads at correct speed but is not complete :
    Code:
    //Déclaration écran
    #define DisplaySerial Serial3                
    #include "Diablo_Serial_4DLib.h"      
    #include "Diablo_Const4D.h"
    #define RESETLINE 4
    
    //Déclaration Lecteur
    
    #define MAX_BITS 100                 // max number of bits
    #define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse. 
    
    // Variables lecteur
    unsigned char databits[MAX_BITS];    // stores all of the data bits
    unsigned char bitCount;              // number of bits currently captured
    unsigned char flagDone;              // goes low when data is currently being captured
    unsigned int weigand_counter;        // countdown until we assume there are no more bits
    unsigned long cardCode=0;            // decoded card code 
    unsigned char i;
    
    
    // Variables écran
    int x;
    int y;
    int touch;
    char *nom;
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    //Fonctions lecteur
    void ISR_INT0()
    {
      //Serial.print("0");
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME; 
    
    }
    
    // interrupt that happens when INT1 goes low (1 bit)
    void ISR_INT1()
    {
      //Serial.print("1");
      databits[bitCount] = 1;
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME; 
    }
    
    //Initialisation
    void setup () {
        DisplaySerial.begin(9600);
        Display.gfx_ScreenMode(LANDSCAPE);
        Display.putstr("Initialisation en cours");
        delay(500);
        pinMode(2, INPUT_PULLUP);      // DATA0 (INT0)
        pinMode(3, INPUT_PULLUP);      // DATA1 (INT1)
        Serial.begin(9600);
        attachInterrupt(0, ISR_INT0, FALLING); 
        attachInterrupt(1, ISR_INT1, FALLING);
        weigand_counter = WEIGAND_WAIT_TIME;
        delay(5000);
        intro ();
    }
    
    void intro(void) {
      Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
      Display.gfx_Cls() ;
      Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
      Display.txt_FGcolour(BLACK) ;
      Display.putstr("                                                                                                                        ");
      Display.putstr("Bonjour. Veuillez passez votre badge devant le lecteur") ;
      Display.txt_FGcolour(LIME) ; // reset
    }
    
    void loop()
    { 
      if (!flagDone) 
      {
        if (--weigand_counter == 0)
          flagDone = 1;  
      }
    
     if (bitCount > 0 && flagDone) {
        unsigned char i;
    
        if (bitCount == 32) {
            for (i=2; i<31; i++)
            {
               cardCode <<=1;
               cardCode |= databits[i];
            }
              conditions();
        }
    
    
         // cleanup and get ready for the next card
         bitCount = 0;
         cardCode = 0;
         for (i=0; i<MAX_BITS; i++)
         {
           databits[i] = 0;
         }
      }
    }
    
    void conditions()
    {
         if (cardCode == 26741719) {
           nom = "Oumy";
           affichage ();
          }
          else if ( cardCode == 26759498) {
           nom = "Francois";
           affichage();
          }
    }
    
    
    void affichage(void) {
        Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
        Display.gfx_Cls() ;
        Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
        Display.txt_FGcolour(BLACK) ;
        Display.putstr("                                                                                                                            ");
        Display.putstr("Bonjour");    //This displays at correct speed whereas in the big code it takes too much time
        Display.putstr (" ");
        Display.putstr(nom);
        Display.putstr(".");
        Display.putstr(" ");
        Display.putstr("Que souhaitez-vous faire ?") ;
        Display.txt_FGcolour(LIME) ; // reset
        Display.gfx_BevelShadow(3) ; // make it really dark
        Display.gfx_BevelWidth(20) ; // make the button bigger by increasing the bevel size for (i = 1; i <= 10; i++) { Display.gfx_Button(ON, 120,50, BLUE, WHITE, FONT3, 1, 1, "Smile") ;
        delay(100) ;
        Display.gfx_Button(ON, 120,200, BLUE, WHITE, FONT3, 1, 1, "Emprunter") ;
        delay(100);
        Display.gfx_Button(ON, 500, 200, BLUE, WHITE, FONT3, 1, 1, "Restituer") ;
        delay(100) ;
    }

  • oumyth
    commented on 's reply
    Thank you so much !! It works correctly now thank you ! You've been a great help :D

    I have tried modifying it a bit to fit with my project : Screen displays "pass your card", User passed his card to a reader, and if recognized the user has two buttons. When choosing one of the buttons it displays something different. Here's my code, everything goes well, everything works fine, except the screen's response is too slow. Could you tell me what can I do to avoid having slow speed response ?

    Code:
     
    //Screen
    #define DisplaySerial Serial3                
    #include "Diablo_Serial_4DLib.h"      
    #include "Diablo_Const4D.h"
    #define RESETLINE 4
    //Touch
    int x ;
    int y;
    int touch;
    int buttonPressed ;
    int statoTouch; 
    int cooX;
    int cooY;
    int tcount;
    
    //Reader
    #define MAX_BITS 100                 // max number of bits
    #define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse. 
    unsigned char databits[MAX_BITS];    // stores all of the data bits
    unsigned char bitCount;              // number of bits currently captured
    unsigned char flagDone;                       // goes low when data is currently being captured
    unsigned int weigand_counter;        // countdown until we assume there are no more bits
    unsigned long cardCode=0;            // decoded card code 
    unsigned char i;
    
    
    // Screen
    char *nom;
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    //Reader functions
    void ISR_INT0() {
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME; 
      }
    
    
    void ISR_INT1() {
      databits[bitCount] = 1;
      bitCount++;
      flagDone = 0;
      weigand_counter = WEIGAND_WAIT_TIME; 
      }
    
    
    void setup () {
        DisplaySerial.begin(9600);
        pinMode(RESETLINE, OUTPUT);
        digitalWrite(RESETLINE, HIGH);
        delay(200);
        digitalWrite(RESETLINE, LOW);
        delay(3500);
        Display.TimeLimit4D=2000;
        Display.gfx_ScreenMode(LANDSCAPE);
        Display.putstr("Initialisation en cours");
        delay(500);
        pinMode(2, INPUT_PULLUP);      // DATA0 (INT0)
        pinMode(3, INPUT_PULLUP);      // DATA1 (INT1)
        Serial.begin(9600);
        attachInterrupt(0, ISR_INT0, FALLING); 
        attachInterrupt(1, ISR_INT1, FALLING);
        weigand_counter = WEIGAND_WAIT_TIME;
        delay(5000);
        intro (); 
        }
    
    void intro(void) {
      Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
      Display.gfx_Cls() ;
      Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
      Display.txt_FGcolour(BLACK) ;
      Display.putstr("Bonjour. Veuillez passez votre badge devant votre lecteur") ; //This is where I ask to pass the card in front of the reader. Everything works until here !
      Display.txt_FGcolour(LIME) ; // reset 
      }
    
    
    void loop() {
      if (!flagDone) {
        if (--weigand_counter == 0)
          flagDone = 1;
          }
    
     if (bitCount > 0 && flagDone) {
        unsigned char i;   
        if (bitCount == 32) {
            for (i=2; i<31; i++) {
               cardCode <<=1;
               cardCode |= databits[i];
               }
              conditions();
              }
         bitCount = 0;   // Resets the reader
         cardCode = 0;
         for (i=0; i<MAX_BITS; i++) {
           databits[i] = 0; 
           }
           }
           hello();
           }
    
    void conditions()
    {
         if (cardCode == 26741719) {
           nom = "Oumy";
           affichage(); 
           }
    
          else if ( cardCode == 26759498) {
           nom = "Francois";
           affichage(); 
           }
    }
    
    
    void affichage(void) {
        Display.gfx_BGcolour(LIGHTGOLD) ; 
        Display.gfx_Cls() ;
        Display.txt_BGcolour(LIGHTGOLD) ;
        Display.txt_FGcolour(BLACK) ;
        Display.putstr(" ");
        Display.putstr("Bonjour"); //This is where it  gets too slow. I only get this displays like 2 minutes after passing the card in front of the reader. Everything afterwards goes at correct speed.
        Display.putstr (" ");
        Display.putstr(nom);
        Display.putstr(".");
        Display.putstr(" ");
        Display.putstr("Que souhaitez-vous faire ?") ;
        Display.txt_FGcolour(LIME) ; // non obligatoire
        Display.gfx_BevelShadow(3) ; // make it really dark
        Display.gfx_BevelWidth(20) ; // make the button bigger by increasing the bevel size for (i = 1; i <= 10; i++) { Display.gfx_Button(ON, 120,50, BLUE, WHITE, FONT3, 1, 1, "Smile") ;
        delay(100) ;
        Display.gfx_Button(OFF, 120,200, BLUE, WHITE, FONT3, 1, 1, "Emprunter") ;
        delay(100);
        Display.gfx_Button(OFF, 500, 200, BLUE, WHITE, FONT3, 1, 1, "Restituer") ;
        delay(100) ;
        Display.touch_Set(TOUCH_ENABLE);
        Display.touch_DetectRegion(0, 0, 800, 480);}
    
    
    void hello(void) {
        Serial.println(tcount);
        tcount ++;
        touch = Display.touch_Get(TOUCH_STATUS);
        Display.gfx_MoveTo(0,0);
        Display.print(touch);
        if(touch == TOUCH_PRESSED)
        {
         x = Display.touch_Get(TOUCH_GETX);
         y = Display.touch_Get(TOUCH_GETY);
        if ( x > 120 && x < 254 && y > 200 && y < 260 ) // first buttons' coordinates
        {
         Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
         Display.gfx_Cls() ;
         Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
         Display.txt_FGcolour(BLACK) ;
         Display.putstr("Votre emprunt a bien ete pris en compte") ;
         buttonPressed = 1;
        }
       else if ( x > 500 && x < 632 && y > 200 && y < 260 ) //second buttons' coordinates
       {
       Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
       Display.gfx_Cls() ;
       Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
       Display.txt_FGcolour(BLACK) ;
       Display.putstr("Votre restitution a bien ete pris en compte") ;
       buttonPressed = 2;
       }
       delay(3000);
       Display.gfx_BGcolour(LIGHTGOLD) ; // réinitialize the screen
       Display.gfx_Cls() ;
       Display.txt_BGcolour(LIGHTGOLD) ; 
       Display.txt_FGcolour(BLACK) ;
       Display.putstr("Bonjour. Veuillez passez votre badge devant votre lecteur") ;
       Display.txt_FGcolour(LIME) ; 
       }
        }
    Thank you again for your help !!

    Best regards,
    Oumy

  • pauleilio
    replied
    Hi Oumy,

    Could you please try this. I've tested it on a different platform and it worked fine after adding the required line of code.

    Code:
    #define DisplaySerial Serial3
    #include "Diablo_Serial_4DLib.h"
    #include "Diablo_Const4D.h"
    
    #define RESETLINE 4
    
    int x;
    int y;
    int touch;
    int buttonPressed;
    int statoTouch;
    int cooX;
    int cooY;
    int tcount;
    
    //SoftwareSerial DisplaySerial(26, 27);
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    void setup () {
    DisplaySerial.begin(9600);
    //Serial.begin(9600);
    pinMode(RESETLINE, OUTPUT);
    digitalWrite(RESETLINE, HIGH);
    delay(200);
    digitalWrite(RESETLINE, LOW);
    delay(3500);
    Display.TimeLimit4D = 2000 ; // *** This is what we were missing ***
    Display.gfx_ScreenMode(LANDSCAPE);
    Display.putstr("Hello");
    
    action();
    }
    
    
    void action(void)
    {
    int i ;
    Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
    Display.gfx_Cls() ;
    Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
    Display.txt_FGcolour(BLACK) ;
    Display.putstr("Hello") ;
    Display.txt_FGcolour(LIME) ; // reset
    Display.gfx_BevelShadow(3) ; // make it really dark
    Display.gfx_BevelWidth(20) ; // make the button bigger by increasing the bevel size for (i = 1; i <= 10; i++) { Display.gfx_Button(ON, 120,50, BLUE, WHITE, FONT3, 1, 1, "Smile") ;
    delay(100) ;
    Display.gfx_Button(OFF, 120, 200, BLUE, WHITE, FONT3, 1, 1, "---Smile--") ;
    delay(100);
    Display.gfx_Button(OFF, 500, 200, BLUE, WHITE, FONT3, 1, 1, "---Cry---") ;
    delay(100) ;
    Display.touch_Set(TOUCH_ENABLE);
    
    Display.touch_DetectRegion(0, 0, 800, 480); //display's resolution (70DT-AR)
    }
    
    void loop()
    {
    //Display.touch_DetectRegion(0, 0, 800, 480); //display's resolution (70DT-AR)
    Serial.println(tcount);
    tcount ++;
    touch = Display.touch_Get(TOUCH_STATUS);
    Display.gfx_MoveTo(0, 0);
    Display.print(touch);
    if(touch == TOUCH_PRESSED)
    {
    x = Display.touch_Get(TOUCH_GETX);
    y = Display.touch_Get(TOUCH_GETY);
    if ( x > 120 && x < 254 && y > 200 && y < 260 ) // first buttons' coordinates
    {
    //delay(100);
    //Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
    //Display.gfx_Cls() ;
    //Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
    //Display.txt_FGcolour(BLACK) ;
    //Display.txt_FGcolour(LIME) ; // reset
    //Display.gfx_BevelShadow(3) ; // make it really dark
    //Display.gfx_BevelWidth(20) ; // make the button bigger by increasing the bevel size for (i = 1; i <= 10; i++) { Display.gfx_Button(ON, 120,50, BLUE, WHITE, FONT3, 1, 1, "Smile") ;
    //delay(100) ;
    Display.gfx_Button(ON, 120, 200, WHITE, BLUE, FONT3, 1, 1, "You smiled") ;
    buttonPressed = 1;
    //delay(100) ;
    }
    else if ( x > 500 && x < 632 && y > 200 && y < 260 ) //second buttons' coordinates
    {
    //delay(100);
    //Display.gfx_BGcolour(LIGHTGOLD) ; // to check CLS works with different bg color
    //Display.gfx_Cls() ;
    //Display.txt_BGcolour(LIGHTGOLD) ; // to ensure text goesn look odd
    //Display.txt_FGcolour(BLACK) ;
    //Display.txt_FGcolour(LIME) ; // reset
    //Display.gfx_BevelShadow(3) ; // make it really dark
    //Display.gfx_BevelWidth(20) ; // make the button bigger by increasing the bevel size for (i = 1; i <= 10; i++) { Display.gfx_Button(ON, 120,50, BLUE, WHITE, FONT3, 1, 1, "Smile") ;
    //delay(100) ;
    Display.gfx_Button(ON, 500, 200, WHITE, BLUE, FONT3, 1, 1, "You cried") ;
    buttonPressed = 2;
    //delay(100) ;
    }
    }
    if(touch == TOUCH_RELEASED)
    {
    if(buttonPressed == 1)
    {
    Display.gfx_Button(OFF, 120, 200, BLUE, WHITE, FONT3, 1, 1, "---Smile--") ;
    buttonPressed = 0;
    }
    if(buttonPressed = 2)
    {
    Display.gfx_Button(OFF, 500, 200, BLUE, WHITE, FONT3, 1, 1, "---Cry---") ;
    buttonPressed = 0;
    }
    }
    
    }
    Best regards

    Paul

    Leave a comment:


  • oumyth
    commented on 's reply
    Hello,

    No problem ! Thank you !

    Best regards,
    Oumy
Working...
X