Sir,
We want to know about sample code of how to configure GPIO pins as output, and let we know how to include them for led toggling.
Sir,
We want to know about sample code of how to configure GPIO pins as output, and let we know how to include them for led toggling.
Hi,
You can configure and control GPIOs using the GPIO abstraction API.
Below is an example of how to toggle LED1 on the nRF52 DK every 1 second:
#include "nrf.h"
#include "nrf_gpio.h"
#include "nrf_delay.h"
#define LED1_PIN 17
int main (void)
{
nrf_gpio_cfg_output(LED1_PIN);
nrf_gpio_pin_clear(LED1_PIN);
while(1)
{
nrf_gpio_pin_toggle(LED1_PIN);
nrf_delay_ms(1000);
}
}
You can also have a look at GPIOTE, for more advanced GPIO controlling.
Best regards,
Jørgen
To configure a pin as output you just need to use (Assuming your LED is on pin 29)
#define LED_PIN 29
nrf_gpio_cfg_output(LED_PIN);// Set LED PIN pin as output
To set the pin to High , use
nrf_gpio_pin_set(LED_PIN);
to set the pin to low, use
nrf_gpio_pin_clear(LED_PIN);
to toggle the pin use
nrf_gpio_pin_toggle(LED_PIN);
Note. You need to include "nrf_gpio.h"
Thank you sir for your valuable answer.
Thank you sir. And thanks for your valuable answer
How would you go about using the nrf_gpio_cfg_output to configure pin 1.01 for example on the nRF52840?