How can we make a button with timer that serve a different function?
Example:
press SW_2 once will toggle on/off light.
hold SW_2 for more than 10 seconds will reset CC2530.
Can anyone give a brief me on how to do this? Thanks.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
How can we make a button with timer that serve a different function?
Example:
press SW_2 once will toggle on/off light.
hold SW_2 for more than 10 seconds will reset CC2530.
Can anyone give a brief me on how to do this? Thanks.
I want to execute 'reset' after press and hold button for 5 sec. I still cannot get it to work. This is my code:
#define KEYHOLD_EVT 0x0100 //define event for key hold int KeyPressCnt=0; //declare global variable for joystick hold checking. uint16 zclSampleLight_event_loop( uint8 task_id, uint16 events ) { ..... if ( events & KEYHOLD_EVT ) { if ( HAL_PUSH_BUTTON2()) //=== HAL_KEY_SW_2 { KeyPressCnt++; if (KeyPressCnt>=5) { //Key hold for 5 second zclSampleLight_BasicResetCB(); } else osal_start_timerEx( zclSampleLight_TaskID, KEYHOLD_EVT, 100); } return ( events ^ KEYHOLD_EVT ); } // Discard unknown events return 0; }
osal_start_timerEx uses milli-seconds so you should change osal_start_timerEx( zclSampleLight_TaskID, KEYHOLD_EVT, 100) osal_start_timerEx( zclSampleLight_TaskID, KEYHOLD_EVT, 1000.)
I did that. It still did not work. Is there a sample code to implement hold button anywhere?
Do you add osal_start_timerEx( zclSampleLight_TaskID, KEYHOLD_EVT, 100) in zclSampleLight_HandleKeys() when HAL_KEY_SW_2 is pressed? Using zclSampleLight_HandleKeys as example, you should add red line.
static void zclSampleLight_HandleKeys( byte shift, byte keys )
{
...
if ( keys & HAL_KEY_SW_2 )
{
osal_start_timerEx( zclSampleLight_TaskID, KEYHOLD_EVT, 1000); //trigger KEYHOLD_EVT to start count for key holding.
....
}
...
}