I am trying to read if an input is 0 or 1 but for some reason it takes the first one its offered and then it does not change anymore.
int main(void)
{
nrf_gpio_cfg_output(24);
nrf_gpio_cfg_input(26, NRF_GPIO_PIN_NOPULL);
for(;;)
{
if(nrf_gpio_pin_read(26) == 1)
{
nrf_gpio_pin_toggle(24);
}
}
}
I've also tried to read the input into a variable like this in a while/for loop:
int value = nrf_gpio_pin_read(26);
But for some reason it keeps sticking to either the first value I stored in it or the direction of the pull up/down. I'm a bit at a loss at what to try as the problem seems wierd. I have tried multiple DKs and pins to ensure it wasn't faulty hardware.
EDIT: What i want to be able to do is make something happen depending on if the input is high or low at the moment I read this. It is connected to a comparator that puts either a digital 1 or 0 value on the pin I am using as input.
EDIT: After I thought it worked last time with the code that uses a button and led on the DK I gave the comperator another go but it starts acting up again that it sets the nrf_gpio_pin_read only once in a while/for loop. When I use the code below in combination with an external comperator and I hook the comperator up to a PSU it waits for the condition while(nrf_gpio_pin_read(26) > 0) once afterwards even if I lower the voltage so this is no longer true the blinky light remains.
nrf_gpio_cfg_output(21);
nrf_gpio_cfg_input(26, NRF_GPIO_PIN_NOPULL);
int main(void)
{
nrf_gpio_pin_write(21, 0);
nrf_delay_ms(5000);
for(;;)
{
while(nrf_gpio_pin_read(26) > 0)
{
nrf_gpio_pin_toggle(21);
nrf_delay_ms(500);
}
nrf_gpio_pin_toggle(24);
}
}