Interrupt function trigger at start-up Teensy 3.5

Status
Not open for further replies.

steve1245

New member
Hi, I'm using an interrupt function with a button and I was wondering why my interrupt function is triggered when the Teensy is powered up and I don't even press the button ? I see in my serial monitor "Detect" even if I didn't press it. After the setup, the interrupt function works very well, so I was wondering what could I do to solve this problem ?


Code:
void setup()
{
  pinMode(39, INPUT_PULLDOWN);
  attachInterrupt(digitalPinToInterrupt(39), stop_fct, RISING);
}

void stop_fct()
{
  Serial.println("Detect");
}

void loop()
{

}


Thank you !
 
Probably just a feature of how those interrupts behave when first enabled - gate the behaviour with a flag
that you only set at the end of setup perhaps?
Code:
volatile bool started = false ;
void setup()
{
  pinMode(39, INPUT_PULLDOWN);
  attachInterrupt(digitalPinToInterrupt(39), stop_fct, RISING);
  started = true ;
}

void stop_fct()
{
  if (started)
    Serial.println("Detect");
}
 
Status
Not open for further replies.
Back
Top