user34877: class Pseudo_Interrupt {
  //only cummulative time is important, exact interval is not
  // Class Member Variables
  // These are initialized at startup
  long OffTime = 1000; // milliseconds of off-time
  // These maintain the current state
  unsigned long previousMillis; // will store last time updated

  void Update() {
    // check to see if it's time for an Interrupt
    unsigned long currentMillis = millis();
    if ((currentMillis - previousMillis >= OffTime) {
      //Time to execute the one second code
    }
  }
}


user30005: Yes, if you advance previous millis by 1000 once that comparison is true. 
Setting previous millis to current millis is the wrong approach as it will accumulate timing errors.
edit:
here is a simple piece that hopefully will do what you are trying to do.
//pseudo timer isr
//return 1 if the timer overflows MYTMR_PR
uint8_t mytmr_ovf(void) {
    static uint32_t last_time=0;        //previous time
    uint32_t current_time;

    current_time = millis();            //take current time
    if (current_time - last_time >= MYTMR_PR) {
        last_time += MYTMR_PR;          //update last time
        return 1;                       //indicate overflow
    }
    return 0;                           //indicate no overflow
}

as I suggested earlier, the code is written so that the timer is long-term accurate.
Hope it helps.
edit 2: here is the above code running on a PIC24F, with MYTMR_PR set to 100 (=100ms)
//user loop
void loop(void) {
    //looping around
    if (mytmr_ovf()) digitalWrite(LED, !digitalRead(LED));   //flip the led
}



user313: A function called by your program can do some, but not all, of what an interrupt function does. If you call it frequently enough, you can get timely execution of your "one second code". How frequently you must call it depends on how precisely an execution interval you need. That may require your mainline code to spend more time polling the timer than you can afford; it depends on your particular circumstances.
A true interrupt function will be called nearly immediately on the occurrence of whatever event is set to trigger it. Until then, no time will be taken from your mainline code. 
Whether that is that is an effective substitute depends on your particular situation.
The code you supplied is not syntactically correct and does not compile. Nested functions are not include in C or C++, and in the 'if' statement, the parentheses are unbalanced.

user34877: I have since put the following in a continuous fast loop. When the program gets to it, it executes.   The one second is a little erratic, but the total cumulative is approximately correct.
long OffTime = 1000;     // milliseconds of off-time

// These maintain the current state of the timer
long previousMillis;   // will store last time updated   
long lateMillis;       // how late was it

//----------------------------------------------------------------------

currentMillis = millis();     //correct for millis() overflow
if (currentMillis - previousMillis < 0 )
    currentMillis = currentMillis + 32768;
{
    if (currentMillis - previousMillis >= OffTime - lateMillis )

        // Assume the difference is longer than 1000 milliseconds
        // because the sample time will be late but not by much
        lateMillis = currentMillis - previousMillis - OffTime;

        // Thus, cumulative time is essentially correct 
        //Time to execute the one second code here
        do some code
    else
        return;
    }
// ---------------------------------------------------- 
}  //  End Of Run Repeatedly


user7508: The whole idea is sound, but I would make a few changes:

as explained by Jot in a comment, you have to update previousMillis
inside the if statement. You have two choices:


set it to currentMillis, then OffTime will be the minimum time
between the pseudo-interrupts
increment it by a constant amount, which I would call period, then
this will be the average time between pseudo-interrupts; this is
more similar to how real timer interrupts work

add a constructor for:


making the period user-selectable
making the action of the timer user-selectable via a callback
initializing previousMillis


With those changes, the class will look like:
class Pseudo_Interrupt {
    unsigned long period;
    unsigned long previousMillis;
    void (*callback)();

public:
    Pseudo_Interrupt(void (*callback)(), unsigned long period)
        : period(period), previousMillis(millis()), callback(callback)
    { }

    void update()
    {  
        if (millis() - previousMillis >= period)
        {
            callback();
            previousMillis += period;
        }
    }
};


user34877: Latest Version:  7/6/17
//--------------------------------------------------------
class Pseudo_Interrupt {

{   // These maintain the current state of the timer
public: 
volatile unsigned long previousMillis;   // will store last time updated   
volatile unsigned long lateMillis = 0;       // how late was it
volatile bool CallOneMinute = false; //facilitates while loops, 
}
// to prevent a callback set previousMillis = millis(); periodically within the 'period'
// to start the callback set previousMillis = millis() - period; lateMillis = 0;
volatile unsigned long currentMillis; 
static const unsigned long period = 1000;     // milliseconds of off-time delay
volatile unsigned long delta;
    void (*callback)();
public:
    Pseudo_Interrupt(void (*callback)(), unsigned long period)
        : period(period), previousMillis(millis()), callback(callback)
    { }

    void update()
    {       currentMillis = millis(); 
            CallOneMinute = false
            delta = currentMillis - previousMillis - period
        if (lateMillis + delta >= 0)                         
            lateMillis = delta;
            CallOneMinute = true             
        {
            callback();   // with correction to keep net correct cumulative time
            previousMillis += ( period - lateMillis ); 
    }
};
//----------------------------------------------------------


34877: <pre><code>class Pseudo_Interrupt {
  //only cummulative time is important, exact interval is not
  // Class Member Variables
  // These are initialized at startup
  long OffTime = 1000; // milliseconds of off-time
  // These maintain the current state
  unsigned long previousMillis; // will store last time updated

  void Update() {
    // check to see if it's time for an Interrupt
    unsigned long currentMillis = millis();
    if ((currentMillis - previousMillis &gt;= OffTime) {
      //Time to execute the one second code
    }
  }
}
</code></pre>
 30005: <p>Yes, if you advance previous millis by 1000 once that comparison is true. </p>

<p>Setting previous millis to current millis is the wrong approach as it will accumulate timing errors.</p>

<p>edit:</p>

<p>here is a simple piece that hopefully will do what you are trying to do.</p>

<pre><code>//pseudo timer isr
//return 1 if the timer overflows MYTMR_PR
uint8_t mytmr_ovf(void) {
    static uint32_t last_time=0;        //previous time
    uint32_t current_time;

    current_time = millis();            //take current time
    if (current_time - last_time &gt;= MYTMR_PR) {
        last_time += MYTMR_PR;          //update last time
        return 1;                       //indicate overflow
    }
    return 0;                           //indicate no overflow
}
</code></pre>

<p>as I suggested earlier, the code is written so that the timer is long-term accurate.</p>

<p>Hope it helps.</p>

<p>edit 2: here is the above code running on a PIC24F, with MYTMR_PR set to 100 (=100ms)</p>

<pre><code>//user loop
void loop(void) {
    //looping around
    if (mytmr_ovf()) digitalWrite(LED, !digitalRead(LED));   //flip the led
}
</code></pre>

<p><a href="https://i.stack.imgur.com/TGjAp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TGjAp.png" alt="enter image description here"></a></p>
 313: <p>A function called by your program can do some, but not all, of what an interrupt function does. If you call it frequently enough, you can get timely execution of your "one second code". How frequently you must call it depends on how precisely an execution interval you need. That may require your mainline code to spend more time polling the timer than you can afford; it depends on your particular circumstances.</p>

<p>A true interrupt function will be called nearly immediately on the occurrence of whatever event is set to trigger it. Until then, no time will be taken from your mainline code. </p>

<p>Whether that is that is an effective substitute depends on your particular situation.</p>

<p>The code you supplied is not syntactically correct and does not compile. Nested functions are not include in C or C++, and in the 'if' statement, the parentheses are unbalanced.</p>
 34877: <p>I have since put the following in a continuous fast loop. When the program gets to it, it executes.   The one second is a little erratic, but the total cumulative is approximately correct.</p>

<pre class="lang-cpp prettyprint-override"><code>long OffTime = 1000;     // milliseconds of off-time

// These maintain the current state of the timer
long previousMillis;   // will store last time updated   
long lateMillis;       // how late was it

//----------------------------------------------------------------------

currentMillis = millis();     //correct for millis() overflow
if (currentMillis - previousMillis &lt; 0 )
    currentMillis = currentMillis + 32768;
{
    if (currentMillis - previousMillis &gt;= OffTime - lateMillis )

        // Assume the difference is longer than 1000 milliseconds
        // because the sample time will be late but not by much
        lateMillis = currentMillis - previousMillis - OffTime;

        // Thus, cumulative time is essentially correct 
        //Time to execute the one second code here
        do some code
    else
        return;
    }
// ---------------------------------------------------- 
}  //  End Of Run Repeatedly
</code></pre>
 7508: <p>The whole idea is sound, but I would make a few changes:</p>

<ul>
<li>as explained by Jot in a comment, you have to update <code>previousMillis</code>
inside the <code>if</code> statement. You have two choices:

<ul>
<li>set it to <code>currentMillis</code>, then <code>OffTime</code> will be the <em>minimum</em> time
between the pseudo-interrupts</li>
<li>increment it by a constant amount, which I would call <code>period</code>, then
this will be the <em>average</em> time between pseudo-interrupts; this is
more similar to how real timer interrupts work</li>
</ul></li>
<li>add a constructor for:

<ul>
<li>making the period user-selectable</li>
<li>making the action of the timer user-selectable via a callback</li>
<li>initializing <code>previousMillis</code></li>
</ul></li>
</ul>

<p>With those changes, the class will look like:</p>

<pre class="lang-cpp prettyprint-override"><code>class Pseudo_Interrupt {
    unsigned long period;
    unsigned long previousMillis;
    void (*callback)();

public:
    Pseudo_Interrupt(void (*callback)(), unsigned long period)
        : period(period), previousMillis(millis()), callback(callback)
    { }

    void update()
    {  
        if (millis() - previousMillis &gt;= period)
        {
            callback();
            previousMillis += period;
        }
    }
};
</code></pre>
 34877: <p>Latest Version:  7/6/17</p>

<pre class="lang-cpp prettyprint-override"><code>//--------------------------------------------------------
class Pseudo_Interrupt {

{   // These maintain the current state of the timer
public: 
volatile unsigned long previousMillis;   // will store last time updated   
volatile unsigned long lateMillis = 0;       // how late was it
volatile bool CallOneMinute = false; //facilitates while loops, 
}
// to prevent a callback set previousMillis = millis(); periodically within the 'period'
// to start the callback set previousMillis = millis() - period; lateMillis = 0;
volatile unsigned long currentMillis; 
static const unsigned long period = 1000;     // milliseconds of off-time delay
volatile unsigned long delta;
    void (*callback)();
public:
    Pseudo_Interrupt(void (*callback)(), unsigned long period)
        : period(period), previousMillis(millis()), callback(callback)
    { }

    void update()
    {       currentMillis = millis(); 
            CallOneMinute = false
            delta = currentMillis - previousMillis - period
        if (lateMillis + delta &gt;= 0)                         
            lateMillis = delta;
            CallOneMinute = true             
        {
            callback();   // with correction to keep net correct cumulative time
            previousMillis += ( period - lateMillis ); 
    }
};
//----------------------------------------------------------
</code></pre>
