<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 </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 "identical" 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 <projects-bounces@vicpimakers.ca> on behalf of Mark G. <vpm@palaceofretention.ca><br>
<b>Sent:</b> Sunday, November 15, 2020 7:13:46 PM<br>
<b>To:</b> projects@vicpimakers.ca <projects@vicpimakers.ca><br>
<b>Subject:</b> Re: [VicPiMakers Projects] Make class out of functions</font>
<div> </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. 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>
> I have two "identical" functions for time slicing the Arduino loop. One <br>
> function is called to see if it is time to toggle the LED every second, <br>
> and the other "identical" function is called to see if it is time to <br>
> send a post to the website every few minutes. These functions seem good <br>
> candidates for a single C++ class, and I'm looking for some <br>
> advice, never having coded a class before. Maybe it's a coding <br>
> challenge? I'm using Arduinos millis() which increments continuously and <br>
> the modulus of that, with a different period value passed to the <br>
> functions, to determine when to act. When the modulus remainder is <br>
> smaller than the last time through the loop, it is time to take action. <br>
> (the vertical line in the stairs)<br>
> <br>
> image.png<br>
> <br>
> <br>
> <br>
> Each instance of the class needs its own static variable for the value <br>
> of mod'ed millis() last time through the loop. I would like to write a <br>
> class which I instantiate with NEW for each different period, .... I <br>
> would like to put these in a library that I could include in any of my <br>
> projects that need time sliced<br>
> <br>
> Here is how I have coded it as functions:<br>
> <br>
> unsigned long lastPostMillis=0; // the value of the modulus last time <br>
> 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>
> if (isPostTime(minutesBetweenPosts*60000)) { //time to send a Post to <br>
> the website<br>
> ...<br>
> if(isBlinkTime(500)){<br>
> toggle builtin led}<br>
> } // end loop<br>
> -- <br>
> George Bowden, 250-893-7423<br>
> gtbowdeng@gmail.com<br>
> <<a href="mailto:gtbowdeng@gmail.com">mailto:gtbowdeng@gmail.com</a>><br>
> <br>
</div>
</span></font></div>
</body>
</html>