Hi. i am trying to turn ON a LED1 and read its status and then turn ON LED2 based on status of LED1 in nrf52840dk board.
#define led1 28
#define led2 25
#define Button 12
int main(void)
{
NRF_LOG_INFO("========================================================");
NRF_LOG_INFO(" nRF52840 GPIO test");
NRF_LOG_INFO("========================================================\r\n");
nrf_gpio_cfg_input(Button,NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(led1, NRF_GPIO_PIN_PULLDOWN);
nrf_gpio_pin_dir_set(led1, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_clear(led1);
nrf_gpio_pin_dir_set(led2, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_clear(led2);
while (true)
{
if(nrf_gpio_pin_read(Button)==0) //Read GPIO
{
nrf_gpio_pin_set(led1); //Turn ON the LED
}
else
{
nrf_gpio_pin_clear(led1); //Turn OFF the LED
}
if(nrf_gpio_pin_read(led1)==0) //Read GPIO
{
NRF_LOG_INFO("LED Off");
nrf_gpio_pin_clear(led2);
}
else
{
NRF_LOG_INFO("LED On");
nrf_gpio_pin_set(led2);
}
}
}
I have read that we to configure led as "input" to read the state and we have to configure it as "output" pin to change the state.
So I have configured it as input and output both. The code is working. But is this the correct way.
I am using LED2 only to test whether i can read the LED1 pin. Please let me know whether this will cause any problem
I used the Blinky code provided by nrf SDK and made changes.
Thank you.