I’m trying to do the following on a Photon:
- Attach an interrupt to pin A0 with a rising input trigger.
- When the A0 ISR is called, I set a volatile bool flag to true.
- In loop(), I am checking for the bool flag from #2 to set to true.
- When the flag from #2 is true, then I start reading from A0 with analogRead.
- At some point I set the flag from #2 back to false.
This all works correctly, the problem then is it will not function a second time. I never see the A0 ISR get called ever again. My guess is there’s some interaction with A0 having and attached ISR and also being read via analogRead(), which from my understanding also uses interrupts. I’ve even tried detaching the ISR when the flag from #2 is true and then reattaching the ISR when the flag from #2 is set back to false. That doesn’t do anything.
Code basically looks like this (I’ve left out a lot of the other stuff):
volatile bool do_read_adc = false;
void ButtonChangeISR(void)
{
Serial.println("ButtonChangeISR");
do_read_adc = true;
}
void setup()
{
pinMode(A0, INPUT);
attachInterrupt(A0, ButtonChangeISR, RISING);
}
loop
{
if (do_read_adc)
val = analogRead(A0);
// Some code that determines when to set do_read_adc to false
}