Giter Club home page Giter Club logo

timeout's Introduction

TimeOut

Current Version: V4.0

Description

TimeOut is an Arduino library to easily handle non-blocking delays. It is able to store all Timeout instances into a container and sort them to save MCU time at each cycle.

Recommended usage

This library is designed to be used when the Arduino «delay()» could have worked, but you need to be able to do other tasks between the timer's start and it's triggered time.

Non recommended usage: -For very precise and/or time-critical uses. It run into « void loop », so it is dependent of the speed of the loop. It could be a couple of millisecond offset. For time critical timing, use interrupt instead. -For short very short or very long delay : For very short delay, it take some time to sort the container when adding and when triggering a delay, so It could be better to use interrupt for really small delay. For long delay, « millis() » is also not so accurate. There could be a better way. (No test have been done. If people want to do some testing for short and log delay, you could post your result on TimeOut github.)

Version History

Please see this page.

Example use

Please see the /examples/ folder for working examples.

Timeout

TimeOut usage : Callback is triggered only once after being set, after the delay.

  • Start an instance :
TimeOut timeout0; (instance declaration have to be in global scope)
  • Set the timeout :
timeout0.timeOut(10000, callback0); //delay, function callback, could be call inside any function
  • add the handler into void loop :
timeout0.handler(); (you need only one handler for all instance of TimeOut. It have to be put in void loop();)
  • cancel a timeOut :
timeout0.cancel(); 

To set the timeout, there is 2 modes possible : TIMEOUT_NORMAL TIMEOUT_UNDELETABLE

New syntax since v3.0

TIMEOUT::NORMAL 			//timer can be overwriten or cleared, you can just omit it, it have overload
TIMEOUT::UNDELETABLE  		//timer cannot be cleared

===> REMOVED!

TIMEOUT_LOCK //timer cannot be overwriten

TIMEOUT_LOCK_UNDELETABLE //timer cannot be cleared or overwriten

  • Normal mode : You can clear timeout with <cancel()> and overwrite it with a new value . Example :
timeout0.timeOut(10000, callback0); //set time out
delay(1000); //wait a seconde for demonstration
timeout0.timeOut(10000, callback0); //set new timeout time 10 seconde from now
timeout0.cancel();//timeOut have been deleted and callback will not append

TIMEOUT_UNDELETABLE : You can overwrite a timeout like in normal mode but clear() will not work. Example :

timeout0.timeOut(, callback0, TIMEOUT_UNDELETABLE); timeout0.cancel(); //will be ignore and callback will be triggered after delay

Interval

After being set, a callback will be triggered at EACH delay interval.

Interval interval0; (Start an instance)

interval0.interval(1000,intervalPrint0);(set the interval, To change callback or delay, you must cancel() the interval first, could be call inside any function)

interval0.cancel();(cancel an interval, could be call inside any function)

interval0.handler();(you need only one handler for all instance of interval. It have to be put on void loop();)

HINT:

Time macro supporting second, minutes and hour:

  • sc(int), return int*1000 for a second
  • mn(int), return int*60000 for a minute
  • hr(int), return int*3600000 for an hour

For example, for a delay you could do:

unsigned long someDelay = hr(1)+mn(30)+sc(20) //will do 1:30 and 20 second delay
timeout0.timeOut(someDelay, callback0);	

Please Note: The time macro do not support floating point! You can't do: hr(1.5)

timeout's People

Contributors

bulldoglowell avatar leogaggl avatar nitrofmtl avatar rpoisel avatar

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.