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함수 작동하여 상태를 변화 시킨다
아주 유용한 정보네요!