아두이노 자이로 센서 인터럽트 관련해서 질문 드립니다.

전구 2018-09-13 (목) 21:41 5년전 3383  

 

안녕하세요. 아두이노를 처음 다뤄보는 초보자입니다.

 

자이로 센서를 작품에 달아 사용하기 때문에 노트북과 연결시켜 시리얼 모니터에서 키를 눌러 인터럽트를 동작 시키지 못합니다.

그래서 스위치를 달아 스위치가 ON이 되면 자이로 인터럽트를 동작 시키려고 합니다.

 

#define sw 2 

 

volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high

void dmpDataReady() {

    mpuIerrupntt = true;

}

 

void setup(){

...

pinMode(sw, INPUT_PULLUP); 

attachInterrupt(digitalPinToInterrupt(sw), dmpDataReady, FALLING); 

...

}

 

이런식으로 소스를 수정하고 인터럽트핀에 스위치를 달아 동작 시키려는데, 스위치가 인터럽트에 영향을 끼치지 못합니다.

 

스위치를 이용해 인터럽트를 동작 시키는 방법을 알 수 있을까요?

메카리워즈 Image Map

메이커 2018-09-14 (금) 13:26 5년전
인터럽트를 사용할 수 있는 핀이 정해져 있습니다.

const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
volatile int buttonState = 0;        // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, CHANGE);
}

void loop() {
  // Nothing here!
}

void pin_ISR() {
  buttonState = digitalRead(buttonPin);
  digitalWrite(ledPin, buttonState);
}


https://www.allaboutcircuits.com/technical-articles/using-interrupts-on-arduino/
주소

모바일 버전으로 보기