attachInterrupt 인터럽트

BABY CAT·2023년 7월 17일
0

Arduino

목록 보기
14/28

2번핀(인터럽트 핀)에 버튼을 연결

13번핀(LED_BUILTIN)에 led연결


const byte interruptPin = 2;

volatile byte state = LOW;



void setup() {

 pinMode(interruptPin, INPUT_PULLUP);

 attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);

//attachInterrupt(digitalPinToInterrupt(pin), ISR, mode); //인터럽트 시 ISR함수 실행 //mode:인터럽트모드선언

}



void loop() {

 digitalWrite(LED_BUILTIN, state);

}



void blink() {

 state = !state;

}

인터럽트 시 blink함수 실행

버튼을 누르거나 뗄 때 인터럽트 > blink함수 작동하여 상태를 변화 시킨다

1개의 댓글

comment-user-thumbnail
2023년 7월 18일

아주 유용한 정보네요!

답글 달기