<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
<div>
<div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Question please,</div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
If time travel, back / forth etc. Is truly ur goal how would&nbsp;</div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; display: inline !important">I have two &quot;identical&quot; functions for time
<b>slicing</b> the Arduino loop.</span></div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; display: inline !important">Slicing through/cutting the loop achieve ur desired results?</span></div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; display: inline !important">Moreover,</span></div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; display: inline !important"><span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; display: inline !important">unsigned long lastPostMillis=0;
 // the value of the modulus last time through the loop.</span><br style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; display: inline !important">unsigned long lastBlinkMillis=0;</span><br>
</span></div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; display: inline !important"><span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; display: inline !important"><br>
</span></span></div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; background-color: rgb(255, 255, 255); display: inline !important">unsigned = unattributable = just who is doing the time travel? Us, god, me, who?</span><br>
</div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; background-color: rgb(255, 255, 255); display: inline !important">Then the use of the word last in other words, meaning final? Has is that a loop when it has
 a determined end equaling end?</span></div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; background-color: rgb(255, 255, 255); display: inline !important"><br>
</span></div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; background-color: rgb(255, 255, 255); display: inline !important">Just briefed over it so, didnt look closely but these examples in and of themselves r the
 opposite of ur goal, see?</span></div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; background-color: rgb(255, 255, 255); display: inline !important"><br>
</span></div>
<div dir="ltr" style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="caret-color: rgb(0, 0, 0); font-family: -apple-system, HelveticaNeue; font-size: 16px; background-color: rgb(255, 255, 255); display: inline !important">m</span></div>
</div>
<div><br>
</div>
<div class="ms-outlook-ios-signature"></div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Projects &lt;projects-bounces@vicpimakers.ca&gt; on behalf of Mark G. &lt;vpm@palaceofretention.ca&gt;<br>
<b>Sent:</b> Sunday, November 15, 2020 7:13:46 PM<br>
<b>To:</b> projects@vicpimakers.ca &lt;projects@vicpimakers.ca&gt;<br>
<b>Subject:</b> Re: [VicPiMakers Projects] Make class out of functions</font>
<div>&nbsp;</div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi George,<br>
<br>
Here's a quick outline of an ActionTimer class.&nbsp; What<br>
do you make of it?<br>
<br>
Mark<br>
<br>
<br>
On 2020-11-15 6:07 p.m., George Bowden wrote:<br>
&gt; I have two &quot;identical&quot; functions for time slicing&nbsp;the Arduino loop.&nbsp; One <br>
&gt; function is called to see if it is time to toggle the LED every second, <br>
&gt; and the other &quot;identical&quot; function is called to see if it is time to <br>
&gt; send a post to the website every few minutes.&nbsp; These functions seem good <br>
&gt; candidates for a single C++ class, and I'm looking for some <br>
&gt; advice,&nbsp;never having coded a class before.&nbsp; Maybe it's a coding <br>
&gt; challenge? I'm using Arduinos millis() which increments continuously and <br>
&gt; the modulus of that, with a different period value passed to the <br>
&gt; functions, to determine when to act.&nbsp; When the modulus remainder is <br>
&gt; smaller than the last time through the loop, it is time to take action. <br>
&gt; (the vertical line in the stairs)<br>
&gt; <br>
&gt; image.png<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; Each instance&nbsp;of the class needs its own static variable for the value <br>
&gt; of mod'ed millis() last time through the loop.&nbsp; &nbsp;I would like to write a <br>
&gt; class which I instantiate with NEW for each different period, ....&nbsp; I <br>
&gt; would like to put these in a library that I could include in any of my <br>
&gt; projects that need time sliced<br>
&gt; <br>
&gt;&nbsp; &nbsp;Here is how I have coded it as functions:<br>
&gt; <br>
&gt; unsigned long lastPostMillis=0;&nbsp; // the value of the modulus last time <br>
&gt; through the loop.<br>
&gt; unsigned long lastBlinkMillis=0;<br>
&gt; <br>
&gt; bool isPostTime(unsigned long int period){<br>
&gt;&nbsp; &nbsp; if(millis() % period &gt; lastPostMillis) {<br>
&gt;&nbsp; &nbsp; &nbsp; lastPostMillis = millis()% period;<br>
&gt;&nbsp; &nbsp; &nbsp; return true;<br>
&gt;&nbsp; &nbsp; }<br>
&gt;&nbsp; &nbsp; else {<br>
&gt;&nbsp; &nbsp; &nbsp; lastPostMillis = millis() % period;<br>
&gt;&nbsp; &nbsp; &nbsp; return false;<br>
&gt;&nbsp; &nbsp; }<br>
&gt; }<br>
&gt; bool isBlinkTime(unsigned long int period){<br>
&gt;&nbsp; &nbsp; int blinkPeriod = 500;<br>
&gt;&nbsp; &nbsp; if(millis() % blinkPeriod &gt; lastBlinkMillis) {<br>
&gt;&nbsp; &nbsp; &nbsp; lastBlinkMillis = millis()% period;<br>
&gt;&nbsp; &nbsp; &nbsp; return true;<br>
&gt;&nbsp; &nbsp; }<br>
&gt;&nbsp; &nbsp; else {<br>
&gt;&nbsp; &nbsp; &nbsp; lastBlinkMillis = millis()% period;<br>
&gt;&nbsp; &nbsp; &nbsp; return false;<br>
&gt;&nbsp; &nbsp; }<br>
&gt; }<br>
&gt; void setup() {...<br>
&gt; }<br>
&gt; void loop() {<br>
&gt;&nbsp; &nbsp; if (isPostTime(minutesBetweenPosts*60000)) { //time to send a Post to <br>
&gt; the website<br>
&gt;&nbsp; &nbsp; ...<br>
&gt;&nbsp; &nbsp; if(isBlinkTime(500)){<br>
&gt;&nbsp; &nbsp; &nbsp; toggle builtin led}<br>
&gt; } // end loop<br>
&gt; -- <br>
&gt; George Bowden, 250-893-7423<br>
&gt; gtbowdeng@gmail.com<br>
&gt; &lt;<a href="mailto:gtbowdeng@gmail.com">mailto:gtbowdeng@gmail.com</a>&gt;<br>
&gt; <br>
</div>
</span></font></div>
</body>
</html>