1 Reply Latest reply on Aug 17, 2015 12:38 AM by MiguelAngelLV

    Intel Edison Mraa C/C++ Interrupts

    Vignoli

      Hi, I'm a new person interacting with Intel IoT and trying to learn basic things. I've been writing a code, which is intended to execute a interruption whenever led state is changed. This interruption should write "Ok." via console, every time it is run. But I've not been successful, and can't understand why. Some expert could help me, please? I have good ideas of projects, and am very excited.

       

      #include "mraa.hpp"
      #include <iostream>
      #include <stdio.h>
      #include <unistd.h>
      #include <time.h>
      
      using namespace mraa;
      using namespace std;
      
      void exec(void*);
      Gpio* pin_13 = new Gpio(13);
      bool state;
      int main()
      {
          state = 1;
          mraa_init();
          pin_13->dir(DIR_OUT);
          pin_13->isr(EDGE_BOTH,&exec,NULL);
          for(;;){
              state = !state;
              pin_13->write(state);
              sleep(2);
          }
          return MRAA_SUCCESS;
      }
      
      void exec(void* args){
          cout<<"Ok."<<endl;
      }
      
        • 1. Re: Intel Edison Mraa C/C++ Interrupts
          MiguelAngelLV

          I think the inerruptions are only for "in" GPIO. You can try to connect GPIO 12 with GPIO 13 and use this code:

           

          #include <iostream>  
          #include <stdio.h>  
          #include <unistd.h>  
          #include <time.h>  
          
          using namespace mraa;  
          using namespace std;  
          
          void exec(void*);  
          Gpio* pin_13 = new Gpio(13);  
          Gpio* pin_12 = new Gpio(12);
          bool state;  
          int main()  
          { 
              state = 1;  
              mraa_init(); 
              pin_12->dir(DIR_OUT);
              pin_13->dir(DIR_IN); 
              pin_13->isr(EDGE_BOTH,&exec,NULL); 
              for(;;){  
                  state = !state; 
                  pin_12->write(state); 
                  sleep(2);  
              } 
              return MRAA_SUCCESS;  
          } 
          
          void exec(void* args){  
              cout<<"Ok."<<endl;  
          }