Button 带旋转编码器的Arduino Mega 2560中断

Button 带旋转编码器的Arduino Mega 2560中断,button,arduino,interrupt,encoder,isr,Button,Arduino,Interrupt,Encoder,Isr,我开始使用Uno,我在网上找到了一个扶轮图书馆,但当我把项目转移到Mega,并尝试改变它的不同引脚时,它停止了工作。我花了几个小时试图从在线资源中找出mega上的中断引脚,只是找不到任何好的资源来充分解释mega中断引脚 我正试图使用这样的中断 Rotary r = Rotary(10,11); void setup(){ PCICR |= (1 << PCIE0); PCMSK0 |= (1 << PCINT4) | (1 << PCINT5);

我开始使用Uno,我在网上找到了一个扶轮图书馆,但当我把项目转移到Mega,并尝试改变它的不同引脚时,它停止了工作。我花了几个小时试图从在线资源中找出mega上的中断引脚,只是找不到任何好的资源来充分解释mega中断引脚

我正试图使用这样的中断

  Rotary r = Rotary(10,11);
void setup(){
  PCICR |= (1 << PCIE0);
  PCMSK0 |= (1 << PCINT4) | (1 << PCINT5);
  sei();
  }

ISR(PCINT0_vect){
//stuff
}
Rotary r=Rotary(10,11);
无效设置(){

描述了PCICR |=(1Arduino中断。它比您提供的示例代码更易于使用

//Mega2560
// external interrupt int.0    int.1    int.2   int.3   int.4   int.5            
// pin                  2         3      21      20      19      18



void setup()
{
  // interrupt # 0, pin 2
  attachInterrupt(0, myISR, CHANGE); // Also LOW, RISING, FALLING
}

void loop()
{

}

void myISR() // must return void and take no arguments
{
  // stuff
}
您不需要使用
sei();
启用中断,因为
attachInterrupt()
可以为您启用中断。但是您可以使用
cli();
禁用中断,然后使用
sei();
重新启用中断