🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Port arduino mega interrupt code on M5STACK

    Scheduled Pinned Locked Moved Arduino
    1 Posts 1 Posters 3.5k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      cepics
      last edited by cepics

      Hi all, what I have to change in this code to run on M5Stack

      
      float pulsesX, XA_SIG=0, XB_SIG=1, pulsesY, YA_SIG=0, YB_SIG=1;
      
      void setup(){
        attachInterrupt(0, XA_RISE, RISING); // Pin 2
        attachInterrupt(1, XB_RISE, RISING); // Pin 3
        attachInterrupt(4, YA_RISE, RISING); // Pin 19
        attachInterrupt(5, YB_RISE, RISING); // Pin 18
        Serial.begin(115200);
        delay(100);
        Serial.println("Connected"); 
      }//setup
      
      
      void loop(){
       Serial.print("x");
       Serial.print(pulsesX);
       Serial.print("y");
       Serial.print(pulsesY);
       Serial.println("end");
       delay(20);
      }
      
      //X-Axis
      
      void XA_RISE(){
       detachInterrupt(0);
       //delay(1);
       XA_SIG=1;
       
       if(XB_SIG==0){
       pulsesX++;//moving forward
       }
       if(XB_SIG==1){
       pulsesX--;//moving reverse
      }
       attachInterrupt(0, XA_FALL, FALLING);
      }
      
      void XA_FALL(){
        detachInterrupt(0);
        //delay(1);
       XA_SIG=0;
       
       if(XB_SIG==1){
       pulsesX++;//moving forward
       }
       if(XB_SIG==0){
       pulsesX--;//moving reverse
      }
       attachInterrupt(0, XA_RISE, RISING);  
      }
      
      void XB_RISE(){
       detachInterrupt(1);
       //delay(1);
       XB_SIG=1;
       
       if(XA_SIG==1){
       pulsesX++;//moving forward
       }
       if(XA_SIG==0){
       pulsesX--;//moving reverse
      }
       attachInterrupt(1, XB_FALL, FALLING);
      }
      
      void XB_FALL(){
       detachInterrupt(1);
       //delay(1);
       XB_SIG=0;
       
       if(XA_SIG==0){
       pulsesX++;//moving forwar
       }
       if(XA_SIG==1){
       pulsesX--;//moving reverse
      }
       attachInterrupt(1, XB_RISE, RISING);
      }
      
      //Y-Axis
      
      void YA_RISE(){
       detachInterrupt(4);
       //delay(1);
       YA_SIG=1;
       
       if(YB_SIG==0){
       pulsesY++;//moving forward
       }
       if(YB_SIG==1){
       pulsesY--;//moving reverse
      }
      
       attachInterrupt(4, YA_FALL, FALLING);
      }
      
      void YA_FALL(){
        detachInterrupt(4);
        //delay(1);
       YA_SIG=0;
       
       if(YB_SIG==1){
       pulsesY++;//moving forward
       }
       if(YB_SIG==0){
       pulsesY--;//moving reverse
      }
       attachInterrupt(4, YA_RISE, RISING);  
      }
      
      void YB_RISE(){
       detachInterrupt(5);
       //delay(1);
       YB_SIG=1;
       
       if(YA_SIG==1){
       pulsesY++;//moving forward
       }
       if(YA_SIG==0){
       pulsesY--;//moving reverse
      }
       attachInterrupt(5, YB_FALL, FALLING);
      }
      
      void YB_FALL(){
       detachInterrupt(5);
       //delay(1);
       YB_SIG=0;
       
       if(YA_SIG==0){
       pulsesY++;//moving forward
       }
       if(YA_SIG==1){
       pulsesY--;//moving reverse
      }
       attachInterrupt(5, YB_RISE, RISING);
      }
      

      tnks a lot

      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • First post
        Last post