Coder Social home page Coder Social logo

neotimer's People

Contributors

jrullan avatar per1234 avatar smartynov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

neotimer's Issues

Copy constructor

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

?

Get time remaining?

I'm using Neotimer wonder if there's a way to determine how much time is left before the timer expires?

[Help wanted] How would this be done?

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?

Enhancement proposal

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();

/*

  • Checks whether the repeat timer is still running
  • Useful to do something during or not during the total repeat period
  • Usage:
  • if(!timer.repeatRunning()){
  • stop blinking that LED or running that motor
  • }
    */
    boolean Neotimer::repeatRunning(){
    if(this->_times > 0){
    return true;
    }
    return false;
    }

/*

  • Stops a running repeat timer
  • Useful to act on a limitswitch or reached condition
  • Usage:
  • timer.repeatStop()){
    */
    void Neotimer::repeatStop(){
    this->_times = 0;
    }

repeat() requires two calls to restart -> timer become inaccurate

Worst case example

  • interval is set 1 ms;
  • repeat() is called every 1 ms
  • repeat() will return true each 2 ms.

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;
}

Millis overflow and signed longs

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.

Readme and examples don't reflect repeat() behavior

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

Multiple timer

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

Segfault when timer.done() is called before timer.start()

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;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.