const int interruptPin2 = 2; // 초록 버튼
volatile bool isButtonPressed2 = false;
const int interruptPin3 = 3; // 빨간 버튼
volatile bool isButtonPressed3 = false;
void setup() {
Serial.begin(9600);
pinMode(interruptPin2, INPUT_PULLUP); // 초록 버튼 (2번 핀)
pinMode(interruptPin3, INPUT_PULLUP); // 빨간 버튼 (3번 핀)
// 초록 버튼: 상승 에지(RISING)에서 감지
attachInterrupt(digitalPinToInterrupt(interruptPin2), button_pressed3, RISING);
// 빨간 버튼: 하강 에지(FALLING)에서 감지
attachInterrupt(digitalPinToInterrupt(interruptPin3), button_pressed2, FALLING);
Serial.println("Setup is done");
}
void loop() {
if (isButtonPressed2) {
Serial.println("Green Button Pressed!"); // 초록 버튼 누르면 빨간 버튼 출력
isButtonPressed2 = false;
}
if (isButtonPressed3) {
Serial.println("Red Button Pressed!"); // 빨간 버튼 누르면 초록 버튼 출력
isButtonPressed3 = false;
}
}
// ISR (초록 버튼을 누르면 빨간 버튼처럼 동작)
void button_pressed2() {
isButtonPressed2 = true;
}
// ISR (빨간 버튼을 누르면 초록 버튼처럼 동작)
void button_pressed3() {
isButtonPressed3 = true;
}