<div dir="ltr">I have two "identical" functions for time slicing the Arduino loop.  One function is called to see if it is time to toggle the LED every second, and the other "identical" function is called to see if it is time to send a post to the website every few minutes.  These functions seem good candidates for a single C++ class, and I'm looking for some advice, never having coded a class before.  Maybe it's a coding challenge? I'm using Arduinos millis() which increments continuously and the modulus of that, with a different period value passed to the functions, to determine when to act.  When the modulus remainder is smaller than the last time through the loop, it is time to take action. (the vertical line in the stairs)<div><br><div><img src="cid:ii_khjvil570" alt="image.png" width="392" height="254" style="margin-right: 0px;"><br></div><div><br><div><br><div><br><div>Each instance of the class needs its own static variable for the value of mod'ed millis() last time through the loop.   I would like to write a class  which I instantiate with NEW 

for each different period,

....  I would like to put these in a library that I could include in any of my projects that need time sliced </div><div><br></div><div> Here is how I have coded it as functions:</div><div><br></div>unsigned long lastPostMillis=0;  // the value of the modulus last time through the loop.<br>unsigned long lastBlinkMillis=0;<br><br>bool isPostTime(unsigned long int period){<br>  if(millis() % period > lastPostMillis) {<br>    lastPostMillis = millis()% period;<br>    return true;<br>  } <br>  else {<br>    lastPostMillis = millis() % period;<br>    return false;<br>  }<br>} <br>bool isBlinkTime(unsigned long int period){<br>  int blinkPeriod = 500;<br>  if(millis() % blinkPeriod > lastBlinkMillis) {<br>    lastBlinkMillis = millis()% period;<br>    return true;<br>  } <br>  else {<br>    lastBlinkMillis = millis()% period;<br>    return false;<br>  }<br>} <br>void setup() {...<br>}<br>void loop() {<br><div>  if (isPostTime(minutesBetweenPosts*60000)) { //time to send a Post to the website</div><div>  ...<div><div>  if(isBlinkTime(500)){<br>    toggle builtin led}<br></div><div>} // end loop</div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>George Bowden, 250-893-7423<br><a href="mailto:gtbowdeng@gmail.com" target="_blank">gtbowdeng@gmail.com<br></a></div></div></div></div></div></div></div></div></div></div>