1 Reply Latest reply on Jan 19, 2017 5:11 PM by Intel Corporation

    MRAA scope of a GPIO context




      How come the scope of a GPIO context does not extend outside a function? I want to do all my GPIO initialization in a function but it gives an error saying that d_pin is not declared.





      #include <stdio.h>
       #include <unistd.h>
       #include <mraa.h>
       void gpio_init(void) {
       mraa_gpio_context d_pin = NULL;
       d_pin = mraa_gpio_init(100);
       mraa_gpio_dir(d_pin, MRAA_GPIO_OUT);
       int main()
       // select onboard LED pin based on the platform type
       // create a GPIO object from MRAA using it
       // loop forever toggling the on board LED every second
       for (;;) {
       mraa_gpio_write(d_pin, 0);
       mraa_gpio_write(d_pin, 1);
       return MRAA_SUCCESS;
        • 1. Re: MRAA scope of a GPIO context
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi Conor,
          Thanks for your interest in the Intel Joule Platform.
          I appreciate all the information provided, looking at the code you have posted the declaration of the d_pin context is performed inside the function gpio_init(), and you are getting the error message because that context is only accessible in that function, think of it like a local variable.
          Hope this information helps, however, if you have any other question, please let me know.

          1 of 1 people found this helpful