jrullan / neotimer Goto Github PK
View Code? Open in Web Editor NEWNon blocking timer class for Arduino.
License: MIT License
Non blocking timer class for Arduino.
License: MIT License
Is there a reason behind using a copy constructor in the initialization code:
Neotimer mytimer = Neotimer(1000); // Set timer's preset to 1s
instead of just
Neotimer mytimer(1000); // Set timer's preset to 1s
?
I'm using Neotimer wonder if there's a way to determine how much time is left before the timer expires?
Hi,
I like this package already and a contnious blink of a led works for example.
Now the question I have is, how would something like this be converted to the neotimer functionalities;
unsigned long previousMillis = 0;
const long interval = 2000; // 2 seconds
while (true) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
ledcWrite(3, 1024);
vTaskDelay(100);
ledcWrite(3, 0);
vTaskDelay(100);
ledcWrite(3, 1024);
vTaskDelay(100);
ledcWrite(3, 0);
}
}
This is what I came up with;
while (true) {
if (allOkTimer.repeat(2)) {
if (digitalRead(LED_GREEN)) {
ledcWrite(3, 0);
} else {
ledcWrite(3, 1024);
}
}
vTaskDelay(1);
}
But that's not doing it....
ANy help please?
Hi,
I'm using your great timer to run a steppermotor (non-blocking) with the esp8266 like:
if (motorTimer.repeat (steps, speed)) {
stepMotorCW();
}
I need however to know whether the repeat is still running and I need to be able to stop the repeat when a limitswitch is reached. I therefor propose 2 more methods to add. You'll find them below.
Kind regards, Ed
boolean repeatRunning();
void repeatStop();
/*
/*
Worst case example
current implementation
boolean Neotimer::repeat(){
if(this->done()){
this->reset();
return true;
}
if(!this->_timer.started){
this->_timer.last = millis();
this->_timer.started = true;
this->_waiting = true;
}
return false;
}
suggested implementation
bool Neotimer::repeat(){
bool ret = false;
if(this->done()){
this->reset();
ret = true;
}
if(!this->_timer.started){
this->_timer.last = _millis.get();
this->_timer.started = true;
this->_waiting = true;
}
return ret;
}
This is how it is determined that the time interval has expired. I am uncertain whether that will behave correctly when millis
rolls over. (Like described here)
Shouldn't the time
and last
variable be stored as unsigned long
to work? (ref)
But I might also just have a faulty reasoning, but I'd like to use this library in a long running application, so I wanted to bring this up.
Its advisable to use volatile variables in ISR.
Is it 'safe' to address Neotimer timers in ISR?
Hello,
The default behavior of repeat()
was changed in the commit on Aug 13, 2017. The readme and examples don't reflect the change, passing an int to repeat()
now causes it to repeat that many times, rather than the repeat happening that many milliseconds.
The readme should use mytimer.repeat()
rather than mytimer.repeat(2000)
, and this is also true in the repeat.ino example.
-Nick
Hi,
Nice library !
I have tried to use multiple timers (declaration seems ok) :
for (int i = 0; i < 13; i++) { Neotimer timer[i] = Neotimer(temps[i]); }
with times constants :
const unsigned int temps[13] = {2500, 2500, 2500, 3500, 3500, 2500, 2500, 2500, 2000, 2500, 2500, 2000, 2000};
but when I call function :
timer[0].start();
it doesn't work, compilator said :
exit status 1
'timer' was not declared in this scope
What have I miss understood ?
Is it possible to do that ?
Best regards,
Stéphane
When creating a new timer _timer.started is left uninitialised, it will be set when .start() is called.
If after initialisation .done() is called a segfault occurs and the sketch crashes.
it can be solved quickly by defining _timer.started during initialisation.
//Default constructor
Neotimer::Neotimer(){
this->_timer.time = 1000; //Default 1 second interval if not specified
this->_timer.started = false;
}
Neotimer::Neotimer(long _t){
this->_timer.time = _t;
this->_timer.started = false;
Uploading basic example code doesn't seems to work in ESP8266. I get Timer finished
repeatedly after every ~millisecond. Is it expected, or is a bug ?
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.