Port arduino mega interrupt code on M5STACK
-
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