Start stop button ?

Dear Members,

How can I make a start/stop button with 1 button ?

Here's my handler :

void bsp_event_handler(bsp_event_t event)
{
    switch (event)
    {
        case BSP_EVENT_SLEEP:
            nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
            break;
				
				 case BSP_EVENT_KEY_0:
					 NRF_LOG_INFO("BSP_EVENT_KEY 0 PUSH ON\n");
            if (actual_state != BSP_INDICATE_FIRST)
                actual_state--;
						    //NRF_LOG_INFO("BSP_EVENT_KEY 0 PUSH ON\n"); //2Mar22 Rixtronix LAB
            else
                actual_state = BSP_INDICATE_LAST;
						    NRF_LOG_INFO("BSP_EVENT_KEY 0 PUSH OFF\n"); //2Mar22 Rixtronix LAB
            break;
            ............

Any clues ?

Kind regards,

Rixtronix LAB

Parents
  • Hello,

    I am not sure what you are doing with the actual_state and BSP_INDICATE_FIRST, but perhaps you could use the bsp_event_to_button_action_assign function to assign a bsp event like BSP_EVENT_KEY_0 to a buttonpress, and then in the handler check if the state is either active or not, inverse it, and perform some other function?
    Something similar to this:

    #define STATE_ON 1
    #define STATE_OFF 0
    ..
        case BSP_EVENT_KEY_0:
            if(state)
            {
                OFF_function();
                state = STATE_OFF;
            }
            else
            {
                ON_function();
                state = STATE_ON;
            }
    ..


    Best regards,
    Karl



Reply
  • Hello,

    I am not sure what you are doing with the actual_state and BSP_INDICATE_FIRST, but perhaps you could use the bsp_event_to_button_action_assign function to assign a bsp event like BSP_EVENT_KEY_0 to a buttonpress, and then in the handler check if the state is either active or not, inverse it, and perform some other function?
    Something similar to this:

    #define STATE_ON 1
    #define STATE_OFF 0
    ..
        case BSP_EVENT_KEY_0:
            if(state)
            {
                OFF_function();
                state = STATE_OFF;
            }
            else
            {
                ON_function();
                state = STATE_ON;
            }
    ..


    Best regards,
    Karl



Children
No Data
Related