اینم کل کد برای اینکه شما هم امتحانش کنید :
کد:
const int interrupt_buttonPin = 3;
volatile int buttonState[]= {0,0};         // variable for reading the pushbutton status
int Treshold=40;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("begining");
  // initialize digital pin 2 as an output for buzzer pushbutton pin as an input :
  pinMode(interrupt_buttonPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
 attachInterrupt(digitalPinToInterrupt(interrupt_buttonPin), ButtonFun1 ,RISING);
 detachInterrupt(digitalPinToInterrupt(interrupt_buttonPin));
 delay(1000);
 attachInterrupt(digitalPinToInterrupt(interrupt_buttonPin), ButtonFun2 ,RISING);
 detachInterrupt(digitalPinToInterrupt(interrupt_buttonPin));

 Serial.print("Treshold=");Serial.print(Treshold);Serial.print(" \t ");
 Serial.println();delay(1000);
}

void ButtonFun1() {
//  read the state of the pushbutton value:
    Treshold=Treshold+4;
//        buttonState[0] = digitalRead(interrupt_buttonPin);
//        buttonState[1] = digitalRead(interrupt_buttonPin);
//        if (buttonState[0] == HIGH && buttonState[1] == HIGH) {
//          Treshold=Treshold-4;
//        }
while (buttonState[0] == HIGH && buttonState[1] == HIGH) {
    Treshold=Treshold-4;
  }
}

//void ButtonFun2() {
//            Treshold=Treshold-4;
//}