INTERRUPT-ARDUINO

Photo of author

By Jackson Taylor

1) Pulse counting using external interrupt interrupt
int c=0;
void setup()
{
  attachInterrupt(0, blink, FALLING);
  Serial.begin(9600);
}
void loop()
{
delay(1000);
Serial.println(c);
c=0;
}
void blink()
{
  c=c+1;
}
2) UART INTERRUPT
//led blinking will off when interrupt occur
int a=0;
void setup() {
  Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop()
{
  if(a==0)
  {
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
  }
  else
  digitalWrite(13,LOW);
}
void serialEvent()
{
 // while (Serial.available()) {
// Serial.write(Serial.read() );
a=1;
    //}
  }