pfeerick / elapsedmillis Goto Github PK
View Code? Open in Web Editor NEWArduino 'port' of the elapsedMillis library
License: MIT License
Arduino 'port' of the elapsedMillis library
License: MIT License
Based on feedback from Matthijs on Arduino developer mailing list
It would be great if this library could be incorporated into PlatformIIO's library manager. I think all that is needed is a library.json file, then register it with PlatformIO.
The main link for documentation for elapsedMillis seems to be https://github.com/pfeerick/elapsedMillis/wiki but it doesn't document the elapsedSeconds code available in the library.
There is advice for installation on https://www.arduino.cc/reference/en/libraries/elapsedmillis/ to:
To use this library, open the Library Manager in the Arduino IDE and install it from there.
Please add that installation line to the wiki.
The elapsedSeconds class is documented in the example and code: https://github.com/pfeerick/elapsedMillis/blob/master/examples/blinkingLeds/blinkingLeds.ino
Line 80 in 765785e
Please add "elapsedSeconds" to the first header in https://github.com/pfeerick/elapsedMillis/wiki
Edit README.md to show:
The elapsedMillis, elapsedMicros, and elapsedSeconds special variable types (objects) automatically increase as time elapses. This makes it easy to check if a certain time has elapsed, while allowing your program to perform other work or checks for user input. It is also very to handle multiple tasks requiring different delays.
This would give more visibility to this library, I think.
Thanks
You are referring to http://playground.arduino.cc//Code/ElapsedMillis instead of http://playground.arduino.cc/Code/ElapsedMillis causing the browser to access http://Code/ElapsedMillis - wich of cause fails.
Curiously, the library does not appear to be functioning on the Intel Edison.
This is a sample code. Does not print to the serial monitor. If I comment out the timer however, it prints just fine.
Any thoughts why this may be the case? I am perplexed.
elapsedMillis stimer0; // global timer
void setup() {
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Waiting...");
while (stimer0 < 1000)
{
//do nothing, just pause
}
}
Good Morning,
I am using an Arduous Mega 2560 board to create a heat staging time delay. The code works fine for short time periods, but delays longer than about 30 seconds make the delay stop working.
I am guessing is that the data type is an int, which only goes up to 32,767 on the Mega. If this is correct, it may be helpful to add this caution the wiki document, or update the data type to unsigned long.
Thank you!
Just rename readme.txt
to readme.md
and github can display the contents of readme with proper format.
PS: I can submit a pull request if needed.
The latest zip has no folder that can be put in libraries, the users have to create their own folder.
please either revert the zip
or preferably
create as zip with just one top level folder called
elapsedMillis
which contains all the files
Kindly move all the files to the root and remove the extra folder.
Most people (including me) just do a git clone in the libraries folder and having an extra library folder messes things.
While you are at it, it will also be really nice if you can change the repo name to just elapsedMills
. Github provides automatic redirect so I guess it shouldn't be an issue.
PS: I can submit a pull request if needed.
The elapsedSeconds class uses millis()*0.001 several times, which requires conversion to float and then back to unsigned long. I changed the expression to millis()/1000, which preserves integer math, and the class works as intended.
Also, elapsedSeconds needs to be added to the Keywords file.
I am having problems printing elapsedMillis object values to the serial port in Arduino avr code, and it appears that this is caused by the object not returning an unsigned long value. The following is a small program to illustrate the problem:
/*
Name: PrintEx_ElapsedMillis.ino
Created: 8/14/2020 9:47:31 AM
Author: FRANKNEWXPS15\Frank
*/
#include <elapsedMillis.h>
#include <print.h> //allows printf-style printout syntax
elapsedMillis sinceLastCheckMsec = 0;
void setup()
{
Serial.begin(115200);
sinceLastCheckMsec = 0;
Serial.printf("small program to demonstrate problems with modified Print.h\n");
Serial.printf("Printing out value of an 'elapsedMillis' object sinceLastCheckMsec, with & without chaining\n");
Serial.printf("Printing out return value from millis(), with & without chaining\n");
Serial.println();
Serial.printf("sinceLastCheckMsec no chaining, no cast: %lu\n", sinceLastCheckMsec);
Serial.printf("sinceLastCheckMsec no chaining, cast to (unsigned long): %lu\n", (unsigned long)sinceLastCheckMsec);
Serial.printf("chaining: millis = %lu\tsinceLastCheckMsec (cast to unsigned long): %lu\n", millis(), (unsigned long)sinceLastCheckMsec);
Serial.printf("chaining: millis: %lu\tsinceLastCheckMsec (no cast): %lu\tsinceLastCheckMsec (cast to unsigned long): %lu\tsinceLastCheckMsec (cast to uint32_t): %lu\n",
millis(), sinceLastCheckMsec, (unsigned long)sinceLastCheckMsec, (uint32_t)sinceLastCheckMsec);
Serial.printf("chaining: millis: %lu\tsinceLastCheckMsec (cast to unsigned long): %lu\tsinceLastCheckMsec (no cast): %lu\tsinceLastCheckMsec (cast to uint32_t): %lu\n",
millis(), (unsigned long)sinceLastCheckMsec, sinceLastCheckMsec, (uint32_t)sinceLastCheckMsec);
Serial.printf("ms: %lu\tChk: %lu\tChk:: %lu\tChk: %lu\n",
millis(), (unsigned long)sinceLastCheckMsec, sinceLastCheckMsec, (uint32_t)sinceLastCheckMsec);
Serial.printf("chaining: millis: %lu\tsinceLastCheckMsec (cast to unsigned long): %lu\tmillis: %lu\tsinceLastCheckMsec (cast to unsigned long): %lu\n",
millis(), (unsigned long)sinceLastCheckMsec, millis(), (unsigned long)sinceLastCheckMsec);
}
void loop()
{
}
When this is run on an Arduino Mega, I get the following output:
Opening port
Port open
small program to demonstrate problems with modified Print.h
Printing out value of an 'elapsedMillis' object sinceLastCheckMsec, with & without chaining
Printing out return value from millis(), with & without chaining
sinceLastCheckMsec no chaining, no cast: 92217847
sinceLastCheckMsec no chaining, cast to (unsigned long): 17
chaining: millis = 22 sinceLastCheckMsec (cast to unsigned long): 22
chaining: millis: 28 sinceLastCheckMsec (no cast): 1843703 sinceLastCheckMsec (cast to unsigned long): 1835008 sinceLastCheckMsec (cast to uint32_t): 0
chaining: millis: 41 sinceLastCheckMsec (cast to unsigned long): 41 sinceLastCheckMsec (no cast): 2695671 sinceLastCheckMsec (cast to uint32_t): 92209152
ms: 55 Chk: 55 Chk:: 3613175 Chk: 0
chaining: millis: 58 sinceLastCheckMsec (cast to unsigned long): 58 millis: 58 sinceLastCheckMsec (cast to unsigned long): 58
I looked at the ellapsedMillis code, but I can't for the life of me see why a reference to an elapsedMillis object doesnt return an 'unsigned long' object, but I'm pretty sure that's what is happening. I use elapsedMillis objects a lot, and it would be nice if I didn't have to remember to always explicitely cast references to 'unsigned long'.
TIA
Frank
I'm actually the author of this code. ;-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.