<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'll have to check further on whether it operates fully correctly. It is still missing actions randomly for some reason. I've attached the main file.</div><div>Thanks for your help. I'll now try to find out why the files won'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. <<a href="mailto:vpm@palaceofretention.ca">vpm@palaceofretention.ca</a>> 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 "const" values).<br>
<br>
<br>
On 2020-11-15 7:13 p.m., Mark G. wrote:<br>
> 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. <br>
>> One function is called to see if it is time to toggle the LED every <br>
>> second, and the other "identical" function is called to see if it is <br>
>> time to send a post to the website every few minutes. These functions <br>
>> seem good 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 <br>
>> and 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 <br>
>> action. (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 <br>
>> a class which I instantiate with NEW for each different period, .... <br>
>> I would like to put these in a library that I could include in any of <br>
>> my 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 <br>
>> to the website<br>
>> ...<br>
>> if(isBlinkTime(500)){<br>
>> toggle builtin led}<br>
>> } // end loop<br>
>> -- <br>
>> George Bowden, 250-893-7423<br>
>> <a href="mailto:gtbowdeng@gmail.com" target="_blank">gtbowdeng@gmail.com</a><br>
>> <mailto:<a href="mailto:gtbowdeng@gmail.com" target="_blank">gtbowdeng@gmail.com</a>><br>
>><br>
> <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>