Virtual delay class outside the Loop()

Hi there, sorry if this is a very nooby question.

Just trying to get a virtual delay working, but all the examples I can find seem to dom it inside the loop() function.

e.g. trying to use the Library from this thread: Class to simplify "blink without delay" - Programming Questions - Arduino Forum

I was just wondering how to use these virtual delay functions in say a BLE callback or other such function, that's not inside the loop()?

I was just wondering how to use these virtual delay functions in say a BLE callback or other such function, that's not inside the loop()?

None of these functions depend on being called inside the loop() routine but usually it's the way to do it. Doing the same stuff directly in a callback usually makes no sense as these aren't run often enough in most cases. But to use the linked library as an example, you can call the reset() method in the callback but do the delayed action in the loop().

Its a small library, why not just add the code to your sketch?

class Elapsed
{
    unsigned long startus, startms;

public:

    // constructor resets time
    Elapsed () 
    {
        reset ();
    };

    // reset time to now
    void reset () 
    {
        startus = micros ();
        startms = millis ();
    };

    // return Elapsed time in milliseconds
    unsigned long intervalMs () 
    {
        return millis () - startms;
    };

    // return Elapsed time in microseconds
    unsigned long intervalUs () 
    {
        return micros () - startus;
    };

};

Thanks all! I read up a bit more on this and realised the right way to do it is have any delays in the main loop().

I've redesigned the code to trigger the delay via setting a global "trigger" variable in callback and the loop "watches for the request" so to speak.

All working as expected now!