Interupts and Serial transmision

I was attempting to use the attachinterupt() function to send a serial message. I noticed that no data gets sent over the period where the interupt is active.
As such i tried to modify a vaiable in my interupt function which gets checked in the loop() but the variable, even though it gets changed within the interupt, it does not get changed into my other functions. I am not familiar with this behavior and i am quite stumped :slight_smile:

Can anyone help me out here?

TIA

You might need to declare the variable as volatile, so that the compiler knows it can be changed at any time. E.g.

volatile int x = 0;

Nope, still did not work. It seems that the variable changes within the interrupt call are changed locally...that the only thing i can get to.
Here is the code i used, i did change the variable to be volatile.

int pin = 13;
volatile boolean bnotify = false;

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(0, detected, FALLING);  
}

void loop()
{
  if( bnotify ){
    Serial.println("Turn Motors ON");
    bnotify = false;
  }
}

void detected()
{
  bnotify = true;
  digitalWrite(pin, HIGH);
  detachInterrupt(0);
}

You forgot the Serial.begin(9600); in your setup(). Once I added that, it worked for me.

OMG, its always the stupid mistakes that get to me :slight_smile:

Thanks for pointing that out :smiley: