Announcement

Collapse
No announcement yet.

How to put a time limite before screen reset

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

  • sherwin4D
    commented on 's reply
    Sure thing.

    Best regards,
    Sherwin

  • oumyth
    commented on 's reply
    Hello,

    Thank you so much for your help !

    I'll test the code as soon as I receive the display. Will keep you updated

    Best regards,
    Oumaïma HOUMANE

  • sherwin4D
    replied
    Hello Oumy,

    You may create another function to count how many seconds have passed since last touch is pressed. Please try code below:
    Code:
    unsigned long currentMillis;
    unsigned long previousMillis;
    int sec = 0;
    
    void countSec() {
    
         currentMillis = millis();
         if (currentMillis - previousMillis >= 1000) {
              sec++;
         }
    
    }
    Once the counter reaches the maximum allowed time, and no touch has been registered, you may turn off the display.
    Code:
    if (sec == 120 && touch != TOUCH_PRESSED) {
         Display.gfx_Contrast(0);
    }
    Please ensure that every time you have a TOUCH_PRESSED, you need to initialize sec back to zero.
    Code:
    if (touch == TOUCH_PRESSED) {
         sec = 0;
         // put other codes here, i.e. set contrast back to non-zero
    }
    I hope this helps.

    Kind regards,
    Sherwin

    Leave a comment:


  • oumyth
    commented on 's reply
    Hello Shewin,

    Thank you fo you detailed answer.

    Originally posted by sherwin4D View Post
    You can turn off the display by setting gfx_Contrast(0)
    That's great ! I wanted to turn off the the display when no touch is detected during 2 minutes. So this function with the appropiate condition works wonders !

    Originally posted by sherwin4D View Post
    You could use millis() function of Arduino to keep track of the time.
    I'm not sure of how to use correctly this function as a condition. I was thinking of something like this to display buttons and enable touch :

    Code:
        Display.putstr("What would you like to do ?") ;
        Display.gfx_BevelShadow(3) ; 
        Display.gfx_BevelWidth(20) ; 
        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);
        touch = Display.touch_Get(TOUCH_STATUS);
        Display.gfx_MoveTo(0,0);
        Display.print(touch);
       // and here I want to add something like if no touch is detected during 2 minutes, then Display.gfx_contrast(0).
        }
    I'm figuring maybe I should use
    Code:
     if(touch !== TOUCH_PRESSED)
    with the millis function, but I'm not sure of how to use both in the same condition.

    Best regards,
    Oumy

  • sherwin4D
    replied
    Hi Oumy,

    Now I'm wondering if there is any line of code I could use that would enable the screen to reset to its initial state if 2 minutes have passed and the user has done no action since starting the program.
    Can you expound a little further on what you meant by 'reset to its initial state'? If what you were wanting to do is reboot the display then, you could use this piece of code:
    Code:
    pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
    digitalWrite(RESETLINE, 1); // Reset the Display via D4
    delay(100);
    digitalWrite(RESETLINE, 0); // unReset the Display via D4
    Or, if you were wanting to show displayed form and objects during initial startup then, you could clear the screen with gfx_Cls() once 2 minutes is over. You could use millis() function of Arduino to keep track of the time.

    I'm also wondering if during this reset, we can make the screen to automatically "turn off" and then turns on to initial state when touch is detected.
    You can turn off the display by setting gfx_Contrast(0). Please refer to page 65 of DIABLO16 Internal Functions Manual for more information on this function. Before turning off the display, you could clear the objects shown and put an empty Userbutton to wake up screeen(set the contrast to non-zero).

    Hope this helps.

    Kind regards,
    Sherwin

    Leave a comment:


  • oumyth
    started a topic How to put a time limite before screen reset

    How to put a time limite before screen reset

    Hello,

    I have a 70-DT screen and an Arduino Mega.
    I have managed to display messages on it, buttons, and can interact with the user.

    Now I'm wondering if there is any line of code I could use that would enable the screen to reset to its initial state if 2 minutes have passed and the user has done no action since starting the program. I'm also wondering if during this reset, we can make the screen to automatically "turn off" and then turns on to initial state when touch is detected.

    Best regards,
    Oumy
Working...
X