<div dir="ltr">Hi Mark<div>The builtin function millis() used in the class could not be found by the compiler so I put the class and member functions in the main file:<div>It now compiles, and operates.  I&#39;ll have to check further on whether it operates fully correctly.  It is still missing actions randomly for some reason.  I&#39;ve attached the main file.</div><div>Thanks for your help.    I&#39;ll now try to find out why the files won&#39;t compile when included in the library.</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Nov 15, 2020 at 8:09 PM Mark G. &lt;<a href="mailto:vpm@palaceofretention.ca">vpm@palaceofretention.ca</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Quick update:<br>
<br>
You probably want to add unsigned in front of<br>
all the long ints, or adjust the type as needed<br>
(all over, including  the &quot;const&quot; values).<br>
<br>
<br>
On 2020-11-15 7:13 p.m., Mark G. wrote:<br>
&gt; Hi George,<br>
&gt; <br>
&gt; Here&#39;s a quick outline of an ActionTimer class.  What<br>
&gt; do you make of it?<br>
&gt; <br>
&gt; Mark<br>
&gt; <br>
&gt; <br>
&gt; On 2020-11-15 6:07 p.m., George Bowden wrote:<br>
&gt;&gt; I have two &quot;identical&quot; functions for time slicing the Arduino loop.  <br>
&gt;&gt; One function is called to see if it is time to toggle the LED every <br>
&gt;&gt; second, and the other &quot;identical&quot; function is called to see if it is <br>
&gt;&gt; time to send a post to the website every few minutes.  These functions <br>
&gt;&gt; seem good candidates for a single C++ class, and I&#39;m looking for some <br>
&gt;&gt; advice, never having coded a class before.  Maybe it&#39;s a coding <br>
&gt;&gt; challenge? I&#39;m using Arduinos millis() which increments continuously <br>
&gt;&gt; and the modulus of that, with a different period value passed to the <br>
&gt;&gt; functions, to determine when to act.  When the modulus remainder is <br>
&gt;&gt; smaller than the last time through the loop, it is time to take <br>
&gt;&gt; action. (the vertical line in the stairs)<br>
&gt;&gt;<br>
&gt;&gt; image.png<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Each instance of the class needs its own static variable for the value <br>
&gt;&gt; of mod&#39;ed millis() last time through the loop.   I would like to write <br>
&gt;&gt; a class which I instantiate with NEW for each different period, ....  <br>
&gt;&gt; I would like to put these in a library that I could include in any of <br>
&gt;&gt; my projects that need time sliced<br>
&gt;&gt;<br>
&gt;&gt;   Here is how I have coded it as functions:<br>
&gt;&gt;<br>
&gt;&gt; unsigned long lastPostMillis=0;  // the value of the modulus last time <br>
&gt;&gt; through the loop.<br>
&gt;&gt; unsigned long lastBlinkMillis=0;<br>
&gt;&gt;<br>
&gt;&gt; bool isPostTime(unsigned long int period){<br>
&gt;&gt;    if(millis() % period &gt; lastPostMillis) {<br>
&gt;&gt;      lastPostMillis = millis()% period;<br>
&gt;&gt;      return true;<br>
&gt;&gt;    }<br>
&gt;&gt;    else {<br>
&gt;&gt;      lastPostMillis = millis() % period;<br>
&gt;&gt;      return false;<br>
&gt;&gt;    }<br>
&gt;&gt; }<br>
&gt;&gt; bool isBlinkTime(unsigned long int period){<br>
&gt;&gt;    int blinkPeriod = 500;<br>
&gt;&gt;    if(millis() % blinkPeriod &gt; lastBlinkMillis) {<br>
&gt;&gt;      lastBlinkMillis = millis()% period;<br>
&gt;&gt;      return true;<br>
&gt;&gt;    }<br>
&gt;&gt;    else {<br>
&gt;&gt;      lastBlinkMillis = millis()% period;<br>
&gt;&gt;      return false;<br>
&gt;&gt;    }<br>
&gt;&gt; }<br>
&gt;&gt; void setup() {...<br>
&gt;&gt; }<br>
&gt;&gt; void loop() {<br>
&gt;&gt;    if (isPostTime(minutesBetweenPosts*60000)) { //time to send a Post <br>
&gt;&gt; to the website<br>
&gt;&gt;    ...<br>
&gt;&gt;    if(isBlinkTime(500)){<br>
&gt;&gt;      toggle builtin led}<br>
&gt;&gt; } // end loop<br>
&gt;&gt; -- <br>
&gt;&gt; George Bowden, 250-893-7423<br>
&gt;&gt; <a href="mailto:gtbowdeng@gmail.com" target="_blank">gtbowdeng@gmail.com</a><br>
&gt;&gt; &lt;mailto:<a href="mailto:gtbowdeng@gmail.com" target="_blank">gtbowdeng@gmail.com</a>&gt;<br>
&gt;&gt;<br>
&gt; <br>
<br>
-- <br>
Projects mailing list<br>
<a href="mailto:Projects@vicpimakers.ca" target="_blank">Projects@vicpimakers.ca</a><br>
<a href="http://vicpimakers.ca/mailman/listinfo/projects_vicpimakers.ca" rel="noreferrer" target="_blank">http://vicpimakers.ca/mailman/listinfo/projects_vicpimakers.ca</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>George Bowden, vice president, Victoria Computer Club<br><a href="mailto:gtbowdeng@gmail.com" target="_blank">gtbowdeng@gmail.com</a></div></div></div>