Chat freely about anything...

User avatar
By LadyDee852
#49730 Learning ESP and C at the same time. I am attempting to read the docs and look at examples to understand the GPIO's better. I can't seem to figure out how this made the LED connected to GPIO # 0 on my feather Huzzah blink. The shift left operation combined with the logical AND operation should give me a either a 0 or 1, but I'm having trouble understanding how that gets us to "look" at that pin.

Also, I read the docs on the gpio_output_set() function, but I don't understand why the shift operation is in there either. (Yes, I am extremely new at this.) If someone could give me a walk-through on what is happening behind the scenes here, it would be so helpful.


static const int pin = 0;

void some_timerfunc(void *arg)
{
//Do blinky stuff
if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & (1 << pin))
{
// set gpio low
gpio_output_set(0, (1 << pin), 0, 0);
}
else
{
// set gpio high
gpio_output_set((1 << pin), 0, 0, 0);
}
User avatar
By martinayotte
#49733 I'm not fluent with Native SDK since I'm using ArduinoESP framework, but it seems a bit obvious to me that you are reading the wrong register :
The GPIO_OUT_ADDRESS is the GPIO output state, you should use the GPIO_IN_ADDRESS register.

But there are also helper macros that ease that too :
#define GPIO_INPUT_GET(gpio_no) ((gpio_input_get()>>gpio_no)&BIT0)