• Stars
    star
    211
  • Rank 186,867 (Top 4 %)
  • Language
    C++
  • License
    MIT License
  • Created over 11 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⏳ Timer Library fully implemented for Arduino DUE

DueTimer

Timer Library to work with Arduino DUE

Installation

  1. Download the Latest release from GitHub.
  2. Unzip and modify the Folder name to "DueTimer" (Remove the '-version')
  3. Paste the modified folder on your Library folder (On your Libraries folder inside Sketchbooks or Arduino software).
  4. Re-open Arduino Software

Getting Started

To call a function handler every 1000 microseconds:

Timer3.attachInterrupt(handler).start(1000);
// or:
Timer3.attachInterrupt(handler).setPeriod(1000).start();
// or, to select whichever available timer:
Timer.getAvailable().attachInterrupt(handler).start(1000);

To call a function handler 10 times a second:

Timer3.attachInterrupt(handler).setFrequency(10).start();

In case you need to stop a timer, just do like this:

Timer3.stop();

And to continue running:

Timer3.start();

There are 9 Timer objects already instantiated for you: Timer0, Timer1, Timer2, Timer3, Timer4, Timer5, Timer6, Timer7 and Timer8.

TIPs and Warnings

Timer4.attachInterrupt(handler).setFrequency(10).start();
// Is the same as:
Timer4.attachInterrupt(handler);
Timer4.setFrequency(10);
Timer4.start();

// To create a custom timer, refer to:
DueTimer myTimer = DueTimer(0); // Creates a Timer 0 object.
DueTimer myTimer = DueTimer(3); // Creates a Timer 3 object.
DueTimer myTimer = DueTimer(t); // Creates a Timer t object.
// Note: Maximum t allowed is 8, as there is only 9 timers [0..8];

Timer1.attachInterrupt(handler1).start(10);
Timer1.attachInterrupt(handler2).start(10);
DueTimer myTimer = DueTimer(1);
myTimer.attachInterrupt(handler3).start(20);
// Will run only handle3, on Timer 1 (You are just overriding the callback)

Timer.getAvailable().attachInterrupt(callback1).start(10);
// Start timer on first available timer
DueTimer::getAvailable().attachInterrupt(callback2).start(10);
// Start timer on second available timer
// And so on...

DueTimer myTimer = Timer.getAvailable();
if (myTimer != DueTimer(0))
// Now we know that the timer returned is actually available
// Can compare timers using == or !=

Compatibility with Servo.h

Because Servo Library uses the same callbacks of DueTimer, we provides a custom solution for working with both of them. However, Timers 0,2,3,4 and 5 will not Work anymore.

You will need uncommend the line in DueTimer.h in DueTimer folder inside the Libraries folder. Uncomment the following line in DueTimer.h:

#define USING_SERVO_LIB	true

Library Reference

You should know:

  • getAvailable() - Get the first available Timer.

  • attachInterrupt(void (*isr)()) - Attach a interrupt (callback function) for the timer of the object.

  • detachInterrupt() - Detach current callback of timer.

  • start(long microseconds = -1) - Start the timer with an optional period parameter.

  • stop() - Stop the timer

  • setFrequency(long frequency) - Set the timer frequency

  • long getFrequency() - Get the timer frequency

  • setPeriod(long microseconds) - Set the timer period (in microseconds)

  • long getPeriod() - Get the timer period (in microseconds)

You don't need to know:

<<<<<<< HEAD

  • int timer - Stores the object timer id (to access Timers struct array).

  • DueTimer(unsigned short _timer) - Instantiate a new DueTimer object for Timer _timer (NOTE: All objects are already instantiated!).

  • static const Timer Timers[] - Stores all timers information

  • static void (*callbacks[])() - Stores all callbacks for all timers

Hardware Information

More information on the Timer Counter module of the µC on the Arduino Due can be found in the documentation file TimerCounter.

More Repositories

1

IAMDinosaur

🦄 An Artificial Inteligence to teach Google's Dinosaur to jump cactus
JavaScript
2,800
star
2

Is-Now-Illegal

🚫 A NERD protest against Trump's Immigration ban
JavaScript
1,372
star
3

node-draftlog

📜 Create mutable log lines into the terminal, and give life to your logs!
JavaScript
1,244
star
4

ArduinoThread

⏳ A simple way to run Threads on Arduino
C++
948
star
5

LinkedList

🔗 A fully implemented LinkedList made to work with general Microcontrollers and Arduino projects
C++
346
star
6

unicute

💙 Cute Unicode symbols. Make the terminal GREAT AGAIN
57
star
7

ArduinoSensors

A Library of Libraries of Sensors. Infrared, Ultrasonic, Compass and many others, ready to work with ArduinoThread and fully object oriented
C++
54
star
8

Gaussian

Library that makes Gaussian work easy to use with C++ and Arduino
C++
52
star
9

BigBang-js

Recreate the BigBang with JavaScript
JavaScript
48
star
10

Robot-Soccer-Simulator

⚽️ An Open-Source Soccer simulator for virtual robots tournaments
Java
34
star
11

EasyFly

A simple and just another Drone Firmware
C++
25
star
12

3DLiveView-ABB

Application using QT and native OpenGL, with a three based rendering engine to show a 3D ABB robot in sync with an arduino
C++
20
star
13

node-require-smart

The smart way of requiring multiple files in NodeJS
JavaScript
18
star
14

ABBNator

ABB Robots, playing TicTacToe with NodeJS in it's free time
JavaScript
16
star
15

Robot-Rescue-2013

RoboCup Junior Rescue B Robot sharing (CAD, Software, Electronics, materials and all stuff)
C
15
star
16

ArdUI

A generic, simple, easy to use User Interface for Arduino
C++
14
star
17

Robot-Soccer-2013

RoboCup Junior Soccer Robot sharing (CAD, Software, Electronics, materials and all stuff)
C
14
star
18

UTFT

A generic LCD Library for Arduino
C
11
star
19

Nao-Taokei

🚫Um app NERD para gerar gifs Huehue BR
JavaScript
6
star
20

NodePlate

Node boilerplate for servers
JavaScript
6
star
21

Robot-Rescue-2012

RoboCup Junior Rescue B Robot sharing (CAD, Software, Electronics, materials and all stuff)
Java
6
star
22

pcb-libraries

Place to keep and share special Altium, Eagle and Proteus components that we create and share with others.
6
star
23

oscilodrawer

Osciloscope Image drawer with Arduino and Nodejs MQTT
C++
5
star
24

Primo

Primo version using Stepper Motors and custom Software
C++
5
star
25

docker-node-python-opencv

A Dockerfile that installs Node.js, Python and OpenCV
4
star
26

tournamenter-obr

Extensão para o Tournamenter que permite pontuar pelo tablet em competições da OBR
JavaScript
4
star
27

easy-admin

Simple Admin UI with CRUD for Node.js
JavaScript
3
star
28

geddy-rest

REST Api made easy for Geddy
JavaScript
3
star
29

Robot-VerySmall-2015

Very Small Robot for 2015 CBR competition
Python
2
star
30

projetohangar

HTML
2
star
31

i23

An innovative way of connecting and communicating sensors with microcontrollers
2
star
32

node-ssl-vision

RoboCup SSL Vision Client library for Node.JS
JavaScript
2
star
33

Robot-Rescue-2011

Emerotecos Team's robot of Rescue A (OBR) 2011
HTML
1
star
34

Phyto-Gear

A simple Arduino robot that communicates with Facebook to notify that it's happy, sad, with or without light...
Arduino
1
star
35

TemPeixeNoRU

App de leitura de cardápio do RU da UFABC
1
star
36

Chenn

An real time graph as learning object for schools
JavaScript
1
star
37

rifa-generator

Projeto antigo de um Gerador de PDF's de Rifas
JavaScript
1
star
38

tournamenter-wro

Tournamenter Plugin for WRO - World Robotics Olympiad
JavaScript
1
star
39

robocup2014

Robocup 2014 Administration panel for leagues
JavaScript
1
star
40

NoFlow

A (really-simple) flow based programming framework
JavaScript
1
star