Announcement

Collapse
No announcement yet.

bugs in simple display code (newbie problem!)

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

  • bugs in simple display code (newbie problem!)

    Hello,

    I have an Arduino Mega 2650 and a 70-DT 4D systems screen (Diablo 16 processor). I'm new to display screens, and for now I just want to display Hello and 2 buttons.

    So I tried coding this using functions found online... but it doesn't work : I have an "exit status 1" problem. I have also looked at the demo examples, but I couldn't find how to solve it.

    Can someone please tell me what have I missed ?

    Attached is a picture of my wiring.

    I'm sorry but I truly am a newbie in coding displays ^^

    Any help would be greatly appreciated !

    Oumy


    Code:
     #define DisplaySerial Serial3
    #include "Diablo_Serial_4DLib.h"
    #include "Diablo_Const4D.h"
    #define RESETLINE 4
    
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    void setup () {
    Display.putstr("Hello");
    }
    
    
    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(RED) ;
    Display.putstr("Choose an action!") ;
    Display.txt_FGcolour(LIME) ; // reset
    Display.gfx_BevelShadow(1) ; // make it really dark
    Display.gfx_BevelWidth(6) ; // make the button bigger by increasing the bevel size
    for (i = 1; i <= 10; i++)
    {
    Display.gfx_Button(ON, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Smile") ;
    delay(100) ;
    Display.gfx_Button(OFF, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Smile") ;
    delay(100) ;
    Display.gfx_Button(ON, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Cry") ;
    delay(100) ;
    Display.gfx_Button(OFF, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Cry") ;
    delay(100) ;
    }}
    Attached Files

  • #2
    Hi,

    Could you try the code below to see if it is any better

    Code:
    #define DisplaySerial Serial3
    #include "Diablo_Serial_4DLib.h"
    #include "Diablo_Const4D.h"
    #define RESETLINE 4
    
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    void setup () {
    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(RED) ;
    Display.putstr("Choose an action!") ;
    Display.txt_FGcolour(LIME) ; // reset
    Display.gfx_BevelShadow(1) ; // make it really dark
    Display.gfx_BevelWidth(6) ; // make the button bigger by increasing the bevel size
    for (i = 1; i <= 10; i++)
    {
    Display.gfx_Button(ON, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Smile") ;
    delay(100) ;
    Display.gfx_Button(OFF, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Smile") ;
    delay(100) ;
    Display.gfx_Button(ON, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Cry") ;
    delay(100) ;
    Display.gfx_Button(OFF, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Cry") ;
    delay(100) ;
    }}
    
    void loop(){
    
    }
    Best regards

    Paul

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      Hello,

      Thank you for your fast answer !

      I have tried your code and it compiles correctly on Arduino. However, when I upload it, the screen doesn't update.
      I can't manage to figure out why?

      Kind regards,
      Oumy

  • #3
    Hi Oumy,

    Sorry, I didn't notice that Serial3 wasn't initialized in the code

    Code:
    #define DisplaySerial Serial3
    #include "Diablo_Serial_4DLib.h"
    #include "Diablo_Const4D.h"
    #define RESETLINE 4
    
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    void setup () {
    DisplaySerial.begin(9600);
    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(RED) ;
    Display.putstr("Choose an action!") ;
    Display.txt_FGcolour(LIME) ; // reset
    Display.gfx_BevelShadow(1) ; // make it really dark
    Display.gfx_BevelWidth(6) ; // make the button bigger by increasing the bevel size
    for (i = 1; i <= 10; i++)
    {
    Display.gfx_Button(ON, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Smile") ;
    delay(100) ;
    Display.gfx_Button(OFF, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Smile") ;
    delay(100) ;
    Display.gfx_Button(ON, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Cry") ;
    delay(100) ;
    Display.gfx_Button(OFF, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "Cry") ;
    delay(100) ;
    }}
    
    void loop(){
    
    }
    Could you please try this first to see if it solves it.

    Best regards

    Paul

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      Works wonders !! Thank you !
      I have another question : I can't figure out the x1, x2, y1 and y2 of the button's coordinates. I know 50 is either y1 or y2, and 120 is either x1 and x2. But how can I get the two other missing coordinates ? (I need them to enable touch functions afterwards)

  • #4
    Hi Oumy,

    Yes, with the buttons the width & height are dependant on the text so it isn't possible to judge where these co-ordinates are.

    One way around it is to use Workshop just to find these co-ordinates. You can start a new project choosing your display and then select Visi as the environment. From the widgets tab click on primitives and then button and then try to re-create the button thats in your code. You will be able to mouse over the bottom right of the button shown to give you these co-ordnates.in the status bar towards the bottom left of workshop.

    I hope this works out for you.

    Best regards

    Paul

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      Hello Paul,

      Thank you very much for your fast response, you're a great help !

      I've been able to determine the coordinated using workshop as you recommended, thank you ! Now, I'm trying to detect when someone touches these buttons, and depending on what button he clicked on, display something.
      I tried coding this however, I have a code error : "exit status 1 : touch_Get was not declared in this scope".

      Here's my code :

      Code:
       
      #define DisplaySerial Serial3
      #include "Diablo_Serial_4DLib.h"
      #include "Diablo_Const4D.h"
      #define RESETLINE 4
      int x;
      int y;
      int touch;
      
      Diablo_Serial_4DLib Display(&DisplaySerial);
      
      void setup () {
      DisplaySerial.begin(9600);
      Display.gfx_ScreenMode(LANDSCAPE);
      Display.putstr("Hello");
      delay(5000);
      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("Choose an action") ;
      Display.txt_FGcolour(LIME) ; // reset
      Display.gfx_BevelShadow(1) ; // make it really dark
      Display.gfx_BevelWidth(6) ; // 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, 230,50, BLUE, WHITE, FONT3, 1, 1, "Cry") ;
      delay(100) ;
      }}
      
      void loop()
      {
        Display.touch_DetectRegion(0,0,240,320);
        Display.touch_Set(TOUCH_ENABLE);
        touch = Display.touch_Get(TOUCH_STATUS);
        Display.putCH(touch);
            if(touch_Get(TOUCH_STATUS)== TOUCH_PRESSED)
               {
                x = touch_Get(TOUCH_GETX);
                y = touch_Get(TOUCH_GETY);
                  if ( x > 120 AND x < 182 AND y > 52 AND y < 69 ) 
                  { 
                    Display.gfx_Button(ON, 230,100, WHITE, BLUE, FONT3, 1, 1, "You smiled") ;
                    delay(100) ;
                  }
                  else if ( x > 230 AND x < 310 AND y > 50 AND y < 69 )
                  {
                   Display.gfx_Button(ON, 230,100, WHITE, BLUE, FONT3, 1, 1, "You cried") ;
                   delay(100) ;
                  }
                  }
               }
      
      
      }
      Could you tell me what have I missed ?

      Best regards,
      Oumy

  • #5
    Hi Oumy,

    Only little things wrong but this should work I hope.

    AND should be replaced && which I have done. Very easy mistake to make and I sometimes find myself doing :D

    touch_Get(TOUCH_GETX); as it's a command from the library it should be preceeded with Display.

    Code:
    #define DisplaySerial Serial3
    #include "Diablo_Serial_4DLib.h"
    #include "Diablo_Const4D.h"
    #define RESETLINE 4
    int x;
    int y;
    int touch;
    
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    void setup () {
    DisplaySerial.begin(9600);
    Display.gfx_ScreenMode(LANDSCAPE);
    Display.putstr("Hello");
    delay(5000);
    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("Choose an action") ;
    Display.txt_FGcolour(LIME) ; // reset
    Display.gfx_BevelShadow(1) ; // make it really dark
    Display.gfx_BevelWidth(6) ; // 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, 230, 50, BLUE, WHITE, FONT3, 1, 1, "Cry") ;
    delay(100) ;
    }
    
    void loop()
    {
    Display.touch_DetectRegion(0, 0, 240, 320);
    Display.touch_Set(TOUCH_ENABLE);
    touch = Display.touch_Get(TOUCH_STATUS);
    Display.putCH(touch);
    if (touch == TOUCH_PRESSED)
    {
    x = Display.touch_Get(TOUCH_GETX);
    y = Display.touch_Get(TOUCH_GETY);
    if ( x > 120 && x < 182 && y > 52 && y < 69 )
    {
    Display.gfx_Button(ON, 230, 100, WHITE, BLUE, FONT3, 1, 1, "You smiled") ;
    delay(100) ;
    }
    else if ( x > 230 && x < 310 && y > 50 && y < 69 )
    {
    Display.gfx_Button(ON, 230, 100, WHITE, BLUE, FONT3, 1, 1, "You cried") ;
    delay(100) ;
    }
    }
    
    }
    Best regards

    Paul

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      Thank you so much !! I'll remember the tips :D

      The program compiles perfectly on Arduino, thank you !

      However, nothing happens when I press on the buttons. I thought at first maybe it's because I have big fingers so I enlarged the detection region area, X and Y's conditions and the buttons' size. I even clicked everywhere on the screen in case I misused the coordinates but nothing happenned. I can't seem to figure out why :/

      Here's the code :

      Code:
      #define DisplaySerial Serial3
      #include "Diablo_Serial_4DLib.h"
      #include "Diablo_Const4D.h"
      #define RESETLINE 4
      int x;
      int y;
      int touch;
      
      Diablo_Serial_4DLib Display(&DisplaySerial);
      
      void setup () {
      DisplaySerial.begin(9600);
      Display.gfx_ScreenMode(LANDSCAPE);
      Display.putstr("Hello");
      delay(5000);
      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("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) ;
      }
      
      void loop()
      {
      Display.touch_DetectRegion(0, 0, 800, 480);
      Display.touch_Set(TOUCH_ENABLE);
      touch = Display.touch_Get(TOUCH_STATUS);
      Display.putCH(touch);
      if(touch == TOUCH_PRESSED)
      {
      x = Display.touch_Get(TOUCH_GETX);
      y = Display.touch_Get(TOUCH_GETY);
      if ( x > 120 && x < 300 && y > 200 && y < 400 )
      {
      Display.gfx_Button(ON, 230, 100, WHITE, BLUE, FONT3, 1, 1, "You smiled") ;
      delay(100) ;
      }
      else if ( x > 500 && x < 600 && y > 200 && y < 400 )
      {
      Display.gfx_Button(ON, 230, 100, WHITE, BLUE, FONT3, 1, 1, "You cried") ;
      delay(100) ;
      }
      }
      
      }

    • oumyth
      oumyth commented
      Editing a comment
      Hello Paul,
      I've tried changing the X and Y conditions to even bigger conditions so I'm sure I'm within either scope when I touch the screen, but nothing happens. So I think the problem doesn't come from the coordinated, but something else, but I can't figure out why.
      I'm using the 70DT-AR screen.

      Here's my code :
      [CODE]
      #define DisplaySerial Serial3
      #include "Diablo_Serial_4DLib.h"
      #include "Diablo_Const4D.h"
      #define RESETLINE 4
      int x;
      int y;
      int touch;

      Diablo_Serial_4DLib Display(&DisplaySerial);

      void setup () {
      DisplaySerial.begin(9600);
      Display.gfx_ScreenMode(LANDSCAPE);
      Display.putstr("Hello");
      delay(5000);
      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(ON, 120,200, BLUE, WHITE, FONT3, 1, 1, "Smile") ;
      delay(100);
      Display.gfx_Button(ON, 500, 200, BLUE, WHITE, FONT3, 1, 1, "Cry") ;
      delay(100) ;
      }

      void loop()
      {
      Display.touch_DetectRegion(0, 0, 800, 480); //display's resolution (70DT-AR)
      Display.touch_Set(TOUCH_ENABLE);
      touch = Display.touch_Get(TOUCH_STATUS);
      Display.putCH(touch);
      if(touch == TOUCH_PRESSED)
      {
      x = Display.touch_Get(TOUCH_GETX);
      y = Display.touch_Get(TOUCH_GETY);
      if ( x > 0&& x < 400 && y > 0&& y < 240 ) // 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, 230, 100, WHITE, BLUE, FONT3, 1, 1, "You smiled") ;
      delay(100) ;
      }
      else if ( x > 400 && x < 800 && y > 240 && y < 480 ) //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, 230, 100, WHITE, BLUE, FONT3, 1, 1, "You cried") ;
      delay(100) ;
      }
      }

      }

  • #6
    Hi Oumy,

    I can't really see anything wrong but will keep looking. I have changed the code if you would like to try.

    Code:
    #define DisplaySerial Serial3
    #include "Diablo_Serial_4DLib.h"
    #include "Diablo_Const4D.h"
    #define RESETLINE 4
    int x;
    int y;
    int touch;
    int buttonPressed;
    
    Diablo_Serial_4DLib Display(&DisplaySerial);
    
    void setup () {
    DisplaySerial.begin(9600);
    Display.gfx_ScreenMode(LANDSCAPE);
    Display.putstr("Hello");
    delay(5000);
    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);
    }
    
    void loop()
    {
    //Display.touch_DetectRegion(0, 0, 800, 480); //display's resolution (70DT-AR)
    
    touch = Display.touch_Get(TOUCH_STATUS);
    //Display.putCH(touch);
    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;
    }
    }
    
    }

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      Hello, thank you for your help and your fast response !
      I've tried the new code but still nothing happens when the button is pressed

      Kind regards,
      Oumy

  • #7
    Hi,

    Ok I will set up a Mega and display and test it here. I'll update you after testing

    Best regards

    Paul

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      Hello,

      Thank you for your help!!

      Keep me updated.

      Best regards,
      Oumy

    • oumyth
      oumyth commented
      Editing a comment
      Hello Paul,

      I've tried different arrangements for the code but still no changes when one of the buttons is pressed. Have you been able to do the testing ?

      Best regards,
      Oumy

  • #8
    Hi Oumy,

    Sorry for the delay, I had a slight issue but can test this today. I will update you very shortly.

    Best regards

    Paul

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      Hello,

      No problem ! Thank you !

      Best regards,
      Oumy

  • #9
    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

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      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

    • oumyth
      oumyth commented
      Editing a comment
      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) ;
      }

  • #10
    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

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      Hello Paul,

      Thank you so much !

      Best regards,
      Oumy

  • #11
    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

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      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

    • oumyth
      oumyth commented
      Editing a comment
      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) ; 
         }
          }

  • #12
    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

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      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; 3 weeks ago.

  • #13
    Ok,

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

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      Thank you very much !!

  • #14
    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);
    }

    Comment


    • oumyth
      oumyth commented
      Editing a comment
      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
Working...
X