Coder Social home page Coder Social logo

timer's Introduction

Timer

The Timer library provides a non-blocking Timer class for Arduino projects.

The Timer class allows you to test for timer completion while allowing other operations to occur. Unlike the delay() function that ties up the CPU until it is complete.

Installation

Clone the git repository into your Arduino/libraries directory

Usage

Include the Timer library

#include <Timer.h>

Define an instance of Timer

Timer timer();

Start the timer. The duration is expressed in milliseconds

timer.start(1000);

Test if timer is complete

if (timer.isComplete()) {
  // do something
}
else {
  // do something else
}

Note: isComplete() willl return true if the timer has never been started

Check how much time is remaining

  unsigned long remaining = timer.remaining();

Example

#include <Timer.h>

Timer timer;

void setup() {
  Serial.begin(9600);
  
  timer.start(1000);
}

void loop() {
  if (timer.isComplete()) {
    Serial.println(F("Timer is complete"));
  }
  else {
    Serial.print(F("Timer is not complete, "));
    Serial.print(timer.remaining());
    Serial.print(F(" remaining"));
  }
  
  // do something else
}

Copyright

Timer is provided Copyright © 2016 Ozbotics under MIT License.

timer's People

Contributors

vannoo67 avatar

Watchers

 avatar  avatar  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.