Announcement

Collapse
No announcement yet.

How to setup a timer for the backlight for gen4-iod-28t

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

  • How to setup a timer for the backlight for gen4-iod-28t

    I have a gen4-iod-28t and wanted to know how to setup a timer so that if there has been no touch after 5 minutes the backlight will turn off. After the backlight turns off, if you touch the screen, the backlight should turn back on.

    I am unable to find any documentation on the proper syntax on how to setup a timer. Are there any code examples for setting up a timer for the backlight or any documentation that I can refer to?

  • #2
    Hi,

    You can do it similar to how you would in any Arduino-compatible device.

    The most common implementation would be to check for the elapsed time and check if the timeout period is reached. In Arduino programming, this is commonly done using the millis() function.

    For example, if you want the display to turn off its backlight after 10 seconds of inactivity


    Code:
    #define INACTIVE_TIMEOUT 10000     // milliseconds

    You will need to record the time when you first started the timeout period. On your setup code, you will need to store the value of millis() in an 'unsigned long' variable. For this discussion, I'll use 'previousMillis'.


    Code:
    previousMillis = millis();    // store current system time during setup

    Be sure that the variable is stored in the global scope since it needs to be updated on your main loop when a touch event occurs. It would also be a good idea to add a variable to store whether the display is active or not.


    Code:
    unsigned long previousMillis = 0;
    boolean displayIsActive = true;

    Your loop will look similar to the example below.


    Code:
    void loop {
    
    gfx.touch_Update();    // required to refresh touch values
    
    int touchStatus = gfx.touch_GetPen();    // get touch status
    
    if (touchStatus != NOTOUCH) {    // if a touch event occurs,
       previousMillis = millis();    // update with current system time when screen is touched
       gfx.BacklightOn(true);       // turn on backlight (if it was off, this acts as wake on touch)
       displayIsActive = true;       // update display active variable
       }
    
    else if (displayIsActive && (millis() - previousMillis >= INACTIVE_TIMEOUT)) {    // if elapsed time reaches timeout while the display is active
          gfx.BacklightOn(false);    // turn off backlight
          displayIsActive = false;    // update display active variable
       }
    
    // do something
    
    }

    You can see my comments above regarding each line. Feel free to modify this as you see fit.

    Best Regards

    Comment

    Working...
    X