This video show how to interrupt a running program. We just need to use attachInterrupt API to achieve our purpose.
Interrupt function for arduino:
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