Photon Interrupts are not Working

Hi Community,

All I want to do is to grab a interrupt from a user button and print something out.

void blink(void);
int ledPin = D1;
volatile int state = LOW;


void setup()
{
  interrupts();
  pinMode(D0, INPUT);
  attachInterrupt(D0, blink, RISING);

  pinMode( ledPin , OUTPUT ); // sets pin as output

}

void loop()
{
  //digitalWrite(ledPin, state);
  Serial.println(digitalRead(D0));
  delay(200);
}

void blink()
{
  Serial.println("Interrupt!!!");
  state = !state;
}

The program looks the same with the example codes in the reference. D0 is the user button. I can even see it turning from 0 to 1 when pressed. But no interrupts generated.

Thank you very much!

You are seeing a floating pin issue.
Use INPUT_PULLDOWN and also a pin that supports interrupts - D0 does not.

https://docs.particle.io/reference/firmware/photon/#attachinterrupt-

Also avoid Serial.print() inside the ISR in real world applications.