GithubHelp home page GithubHelp logo

arduino-definable-interval's Introduction

Arduino Interval Library

By Patrick Pedersen

The goal of this library is to provide a solution for tasks that require some kind of interval pattern, while barely interfearing with the entire runtime time process ulike delays. This is done by Protothreading using time stamps that get checked in an regulare pattern, being the interval. For simple time stamp interreaction, use the time_stamp class that is packed with various useful functions for time_stamp reading and writing. To build a interval, create an instance of definable_interval and refference onInterval to your desired function. This function is then executed on every interval. To start a interval, execute the interval() member function inside of your desired loop. The function will not delay runtime, instead it will skip until the next interval.

interval()

Usage

Including the library :

#include <Interval.h>

Defining a interval with a length of 1 second that executes function f:

void f() {
...
}

definable_interval interval(1000, &f):

Example

Interval that prints "Hello" to the serial output every second while printing the state of pin D3 D4 D5 and D6. No delays involved!

#include <Interval.h>

/* Will be called on Interval */
void hello() {
	Serial.println("Hello");
}

/* Interval that print hello every second */
definable_interval hello_interval(1000, &hello);

void setup() {
	for (int i = 0; i <= 6; i++) {
		pinMode(i, INPUT);
	}

	Serial.begin(9600);
}

void loop() {
	/* Check and execute interval */
	hello_interval.interval();

	/* No delay */

	/* Print Pin states */
	for (int i =0; i <= 6; i++) {
		Serial.println(digitalRead(i);
	}
}

arduino-definable-interval's People

Contributors

ctxz avatar

Watchers

James Cloos 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.