<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Port arduino mega interrupt code on M5STACK]]></title><description><![CDATA[<p dir="auto">Hi all, what I have to change in this code to run on M5Stack</p>
<pre><code>
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);
}
</code></pre>
<p dir="auto">tnks a lot</p>
]]></description><link>https://community.m5stack.com/topic/1186/port-arduino-mega-interrupt-code-on-m5stack</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Mar 2026 00:35:48 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/1186.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Aug 2019 12:30:20 GMT</pubDate><ttl>60</ttl></channel></rss>