Alternative to Delay() within Interrupts?

Hi there,

I’m still struggling with this. Not sure exactly what you mean @ScruffR maybe you can write some pseudocode for me?

I am now unable to get a basic interrupt working. Perhaps I am missing something?

// This #include statement was automatically added by the Particle IDE.
int AC_LOAD = D7;

void setup() {
  // put your setup code here, to run once:
  pinMode(AC_LOAD, OUTPUT);
  attachInterrupt(3, zero_crosss_int, RISING);
  digitalWrite(AC_LOAD,LOW);
  

}



void zero_crosss_int()
{
    digitalWrite(AC_LOAD,HIGH);
    
}

void loop() {

}

I’ve played with the circuit on TINKER and the pin 3 indeed does go high on the zero-cross.

Let me know what you think!

Just a minor one: Don’t use the Arduino pin numbers - use D3 instead.

And you need to set pinMode(D3, INPUT); // or INPUT_PULLUP with a button to GND for testing prior to attaching the interrupt.

What pseudo code? If you apply my commented alterations to your original code, it should build.

If you want to see the interrupt trigger, you should put this line into it digitalWriteFast(AC_LOAD, !pinReadFast(AC_LOAD)); - this will toggle the pin and in a faster way than normal digitalWrite().

1 Like

Thanks. I had D3 originally but thought that it would work if I switched to arduino pins.

I’m sorry but can you tell me how to view your ‘edit’ I’m not sure what you mean, all I can see is your explanation about starting a hardware timer within an interrupt and then triggering a second interrupt? I would like some help with the logic because I don’t quite understand it.

In post #19, I have commented on some errors in your code in post #18.
If you just altered this the code of #18 should at least build - not sure if it would work as intended tho’.

Or what ‘edit’ did you refer to? I’m not quite sure, there are several code snippets and “solutions” in this thread :wink: