Hello!
Using nrf_gpio.h enables P0.00 port control, but using app_timer.h together makes port control impossible.
I don't know if the code I wrote is the problem or not....
#define ON_OFF_DETECT 1
#define HOLD_DETECT 0
#define LED1 11
#define PRESS_BTN_TICKS APP_TIMER_TICKS(100) // 100 ms tick
uint32_t tick = 0;
APP_TIMER_DEF(m_app_timer_id);
static void lfclk_config(void)
{
ret_code_t err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);
nrf_drv_clock_lfclk_request(NULL);
}
static void app_timer_handler(void * p_context)
{
tick++;
}
static void timer_init(void)
{
ret_code_t err_code; err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
err_code = app_timer_create(&m_app_timer_id, APP_TIMER_MODE_REPEATED, app_timer_handler);
APP_ERROR_CHECK(err_code);
}
int main(void)
{
nrf_gpio_cfg_input(ON_OFF_DETECT,NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_output(LED1); nrf_gpio_cfg_output(HOLD_DETECT);
nrf_gpio_pin_set(LED1);
lfclk_config();
timer_init();
while( 1 )
{
if( tick == 0 )
{
if( nrf_gpio_pin_read(ON_OFF_DETECT) == 0)
{
tick = 1;
uint32_t err_code = app_timer_start(m_app_timer_id, PRESS_BTN_TICKS, NULL);
APP_ERROR_CHECK(err_code);
}
}
if( tick >= 30 ) // >= 3 sec ?
{
nrf_gpio_pin_write(HOLD_DETECT,1);
nrf_gpio_pin_set(HOLD_DETECT);
ret_code_t err_code; err_code = app_timer_stop(m_app_timer_id);
APP_ERROR_CHECK(err_code); break;
}
}
Thank you.