int led = 13;
int buttonPin = 2;
volatile bool ledState = LOW;
volatile bool buttonPressed = false;
void setup() {
// put your setup code here, to run once:
pinMode(led,OUTPUT);
pinMode(buttonPin,INPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin),Interrupts,RISING);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(led,HIGH);
Serial.println("Continously ON");
delay(1000);
if (buttonPressed){
digitalWrite(led,LOW);
Serial.println("Interrupt occurs");
delay(1000);
buttonPressed = false;
Serial.println("Interrupt ends");
}
}
void Interrupts() {
buttonPressed = true;
}