Timer
Small library for measuring elapsed time between start and stop command
Install / Use
/learn @sstaub/TimerREADME
Arduino Timer Library v1.1.2
The Arduino Timer Library allows you to measure the time between started and stop command. The time can measured in milli or micro seconds. Micro seconds have only a resolution of 4µs!
Installation
Install directly from the library manager of the Arduino or PlatformIO IDE or do it manually:
- Download from the Release site
- Unzip
- Move the folder to your Arduino Library folder
How to use
First, include the Timer library to your project:
#include "Timer.h"
Now, you can create a new object(s):
Timer timer;
// for micro second resolution:
Timer timer(MICROS);
timer.start(); // start the timer
timer.pause(); // pause the timer
timer.resume(); // resume the timer
timer.stop(); // stops the timer
timer.read(); // gives back the elapsed time in milli or micro seconds
Example
Complete example: Here we created one timer, you can run it and get the result in the Serial monitor.
#include "Timer.h"
Timer timer;
void setup() {
Serial.begin(9600);
timer.start();
if(timer.state() == RUNNING) Serial.println("timer running");
delay(1000);
timer.stop();
if(timer.state() == STOPPED) Serial.println("timer stopped");
Serial.print("time elapsed ms: ");
Serial.println(timer.read());
}
void loop() {
return;
}
Documentation
Constructors / Destructor
Timer(resolution_t resolution = MILLIS)<br> Creates a Timer object
- parameter resolution sets the internal resolution of the Timer, it can MICROS, or MILLIS
~Ticker()<br> Destructor for Ticker object
Functions
void start()<br> Start the Timer. If it is paused, it will restarted the Timer.
void pause()<br> Pause the Timer.
void resume()<br> Resume the Timer after a pause.
void stop()<br> Stops the Timer.
uint32_t read()<br> Returns the time after start, you can read the elapsed time also while running.
status_t state()<br> Get the Timer state (RUNNING, PAUSED, STOPPED).
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
