menu

Back To Home

Wednesday, December 25, 2019

Arduino uno R3-Interrupt


This video show how to interrupt a running program. We just need to use attachInterrupt API to achieve our purpose.

Interrupt function for arduino:

 Switch:




PIN connection:




Arduino program:


volatile int ledon=0;

void setup() {
  // put your setup code here, to run once:
pinMode(13,OUTPUT);
//pinMode(2,INPUT);
attachInterrupt(1,buttonFunc,HIGH);
}

void loop() {

  if(ledon)
  {
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
 
  }

}
void buttonFunc() {
  // put your main code here, to run repeatedly

ledon=1;
}

No comments:

Post a Comment