I am trying to control an led by using the interupt function? and keep the led on for 2 seconds but i cannot include delay funtion.
I
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include "nrf.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "boards.h"
#include "nrf_delay.h"
#ifdef BSP_BUTTON_0
#define PIN_IN BSP_BUTTON_0
#endif
#ifndef PIN_IN
#error "Please indicate input pin"
#endif
#ifdef BSP_LED_0
#define PIN_OUT BSP_LED_0
#endif
#ifndef PIN_OUT
#error "Please indicate output pin"
#endif
#define PIN_1 NRF_GPIO_PIN_MAP(1,1)
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
//nrf_drv_gpiote_out_toggle(PIN_OUT);
nrf_gpio_pin_set(PIN_1);
nrf_delay_ms(2000);
nrf_gpio_pin_clear(PIN_1);
}
/**
* @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
* and configures GPIOTE to give an interrupt on pin change.
*/
static void gpio_init(void)
{
ret_code_t err_code;
// err_code = nrf_drv_gpiote_init();
// APP_ERROR_CHECK(err_code);
//
// nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
//
// err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
// APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}
/**
* @brief Function for application main entry.
*/
int main(void)
{
gpio_init();
nrf_gpio_cfg_output(PIN_1);
while (true)
{
// Do nothing.
}
}
/** @} */