How to hold down button 3s?

Hello friends!
I have 1 push button that wants to run 2 states. 1 Using event clicked on or off control led was successful. When you hold down for 3s to open the messbox. I used the event LV_EVENT_CLIKED and LV_EVENT_LONG_PRESSED_REPEAT no success. Everyone suggested me.

You can save the current tick in LV_EVENT_PRESSED and check how many ticks has been elapsed in LV_EVENT_PRESSING.

E.g.

void my_event(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    static uint32_t t;
    if(code == LV_EVENT_PRESSED) {
        t = lv_tick_get();
    } 
    else if(code == LV_EVENT_PRESSING) {
        if(lv_tick_elaps(t) > 3000) {
            /*Do something*/
        }
    }
}

2 Likes