I added/changed some code below which might help reduce the time delay. I compiled it but did not run it.
First, I would add only the first line to your code and see if it makes a difference. If not, add the rest of the changes and see what happens. The docs referenced in the code below cautions against using most API functions, with the exception of pinSetFast, pinResetFast, and analogRead, within an ISR.
Hope this helps!
SYSTEM_THREAD(ENABLED);// added
#define PIN_OUT D6
#define PIN_IN D19
//volatile bool current;
bool current;// changed
volatile bool triggerDetect = false;// added
void isr_in() {// changed
triggerDetect = true;//Generally, an ISR should be as short and fast as possible.
}
void captureTriggerInfo() {// added
current = !current;
digitalWriteFast(PIN_OUT, current);
digitalWriteFast(PIN_OUT, !current);
digitalWriteFast(PIN_OUT, current);
}
void setup() {
pinMode(PIN_OUT, OUTPUT);
pinMode(PIN_IN, INPUT_PULLDOWN);
attachInterrupt(PIN_IN, isr_in, CHANGE, 0); // highest priority
//https://docs.particle.io/reference/device-os/api/interrupts/attachinterrupt/
current = pinReadFast(PIN_IN);
digitalWriteFast(PIN_OUT, current);
}
void loop() {
if (triggerDetect) {
triggerDetect = false;
captureTriggerInfo();
}
}
added:
BTW, there are two other threads with content I thought were interesting and are worth a look:
@rickkas7 Can the P2 run two Interrupts concurrently? - #4 by rickkas7
&
@peekay123 P2 - GPIO and Interrupt Latency