I’m attempting to use the Push Notification example sketch (on Blynk’s documentation website) with my Photon but I’m running into issues with this command:
attachInterrupt(digitalPinToInterrupt(2), notifyOnButtonPress, CHANGE);
The Photon doesn’t recognize “digitalPinToInterrupt(2)” syntax.
I’ve tried the following which will all complie:
attachInterrupt(D2, notifyOnButtonPress, CHANGE);
attachInterrupt(2, notifyOnButtonPress, CHANGE);
attachInterrupt(V2, notifyOnButtonPress, CHANGE);
but still am unable to Push a Notification when I press the button…My Photon also freezes up if I press the button too many times repeatedly but I believe this is due to the 1 Push msg per minute limit.
Any suggestions would be much appreciated!
Thanks,
-Jp-
In general, you should ask this kind of question on Particle forums.
Anyway, I hope maybe someone from the community can answer it.
Cheers.
Ok so I’ve had a little more time to play with this and here is my discovery:
I can run this code with out the particle Photon freezing up:
#include "blynk/blynk.h"
#define BLYNK_PRINT Serial
volatile int state = LOW;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
attachInterrupt(D7, notifyOnButtonPress, CHANGE);
}
void notifyOnButtonPress()
{
state = !state;
}
void loop()
{
Blynk.run();
}
But the below code will freeze up the Photon and it will no longer respond to commands (and stays solid cyan after the button press, instead of “breathing cyan”) :
#include "blynk/blynk.h"
#define BLYNK_PRINT Serial
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
attachInterrupt(D7, notifyOnButtonPress, CHANGE);
}
void notifyOnButtonPress()
{
Blynk.notify("Yaaay... button is pressed!");
}
void loop()
{
Blynk.run();
}
This leads me to think that the Blynk.notify() command doesn’t play well with the attachInterupt() command??? What do you think the issue could be?
Yes, it may be the problem.
Not all functions may behave well in interrupt context.
You can make a new variable and use it as a flag to run .notify() inside of loop().
Hope that helps.