confused about example code: Lesson2 exercise 1 of nRF Connect SDK Fundamentals

hello community

I`m a beginner, try to test the Lesson2 exercise 1 code of nRF Connect SDK Fundamentals, it´s about LED and buttons.

Thingy53 I`m using, this is the schematic, theoritcally, if button(SW3) is pressed, it´s connected to ground, namely, logic 0. 

button in the code, I actually get logic 1, when the button is pressed, this confuses me, why???

	while (1) {
		/* STEP 6.1 - Read the status of the button and store it */
        bool val = gpio_pin_get_dt(&button);
		printk("button:%d",val);
		/* STEP 6.2 - Update the LED to the status of the button */
        gpio_pin_set_dt(&led,val);

        k_msleep(SLEEP_TIME_MS); // Put the main thread to sleep for 100ms for power optimization
	}


Parents Reply Children
  • Hi,

    I see that you've resolved this yourself already, and yes, you're right. This it how it works.

    You can for instance use the overlay (also explained in the fundamentals course) to change if a GPIO should be active high or active low, to revert this. You can also use the devicetree helper in the VS Code extension to visually see what is happening and these configurations will get directly added to your overlay files if you want to modify something.

    Kind regards,
    Andreas

Related