Welcome to the forum. The Arduino Uno is well known, and there is many code for it. The Nano Every has also a microcontroller from the AVR family, but it is not the same. Could you draw on a piece of paper what you want ? Is there a incoming pulse that is a short time high, and you want to lengt… Answer from Koepel on forum.arduino.cc
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Looking for a timer interrupt library that can change intervals - Programming - Arduino Forum
April 23, 2023 - I can use micros() to get some good information about how long between incoming pulses but have been having trouble finding the right library to handle multiplying that interval using an interrupt timer for better accuracy. I tried the "arduino-timer" library to try this out but based on searching ...
Top answer
1 of 1
4

Don't know if I understand what you want to do. IMHO TimerOne is a good library for repetitive tasks, not for one shot events.

You should use Timer1.stop and Timer1.resume() to start the 3 seconds count whenever you press the button. But TimerOne has a known issue: when you use restart or start the ISR is fired immediatly

Here is my version of your code. It waits for button press and then starts timer. After 3 seconds pressed_check is fired and the longPressDetected flas is set. I hope I have correctly interpreted your question

#include <TimerOne.h>
#define pinButton 3
#define POWER_ON_TIME 3UL //Long press in seconds

volatile unsigned long pressed_Time = 0;
volatile unsigned long myTime_button = 0;
volatile unsigned long myTimeOn_button = 0;
volatile unsigned long myTime_pressed = 0;

volatile bool firstISR_Call = true;
volatile bool longPressDetected = false;

unsigned long holdTime = 0;
bool button_state = false;

void setup() {
    // put your setup code here, to run once:
    pinMode(pinButton, INPUT_PULLUP);
    pinMode(LED_BUILTIN, OUTPUT);

    Timer1.initialize();
    // Create an ISR that is called every POWER_ON_TIME seconds
    Timer1.attachInterrupt(pressed_check, POWER_ON_TIME * 1000000UL);
    // Stop Timer1 now
    Timer1.stop();  
    
    //Timer1.attachInterrupt(pressed_check);

    attachInterrupt(digitalPinToInterrupt(pinButton), button_act, CHANGE);
    Serial.begin(9600);
}

void loop() {
    if (longPressDetected) {
        longPressDetected = false;
        Serial.println("Long press detected");
    }
    delay(100);
}

void button_act() {
    if (!digitalRead(pinButton)) {
        myTime_button = micros(); //Flanco de bajada
        firstISR_Call = true;       // Set to true toprevent "phantom" interrupt
        longPressDetected = false;  // Clear long press detection flag
        Timer1.restart();           // Restart timer from 0 - ISSUE: this fires immediatly an interrupt
                                    // causing a so called "phantom" interrupt
    }
    else { 
      myTimeOn_button = micros() - myTime_button; 
      Timer1.stop();
    } //Flanco de subida
}

void pressed_check() {
    // Detect "phantom" interrupt
    if (firstISR_Call) {
        firstISR_Call = false;
        return;
    }
    longPressDetected = true;
    myTime_pressed = micros() - myTime_button;
    Timer1.stop();
}
🌐
Arduino Libraries
arduinolibraries.info › categories › timing
Timing - Arduino Libraries
A list of the 335 libraries in the category Timing · This website is Open Source, please help improve it by submitting a change on GitHub: https://github.com/njh/arduino-libraries
🌐
GitHub
github.com › taromorimoto › interval-timer
GitHub - taromorimoto/interval-timer: A simple interval timer for Arduino
... #include "IntervalTimer.h" ... { timerA.update(); timerB.update(); } You can just make a zip of the IntervalTimer folder and add as a library in Arduino IDE....
Forked by 2 users
Languages   C++ 100.0% | C++ 100.0%
🌐
GitHub
github.com › taoyuan › Timers
GitHub - taoyuan/Timers: A hardware timer library for Arduino · GitHub
#include <Timers.h> HardwareTimer &Timer = Timer1; // Could be Timer1, Timer2 or Timer3 // This example uses the timer interrupt to blink an LED // and also demonstrates how to share a variable between // the interrupt and the main program. const int led = RGB_BUILTIN_R; // the pin with a LED void setup(void) { pinMode(led, OUTPUT); Timer.init(150000); // Timer2 only support below 16.384 ms interval Timer.attachInterrupt(blinkLED); // blinkLED to run every 0.15 seconds Serial.begin(115200); } // The interrupt will blink the LED, and keep track of how many times it has blinked.
Author   taoyuan
🌐
GitHub
github.com › brunocalou › Timer
GitHub - brunocalou/Timer: Arduino timer library · GitHub
#include "timer.h" #include ... all the timers at once TimerManager::instance().update(); ... void setInterval(unsigned long interval, int repeat_count=-1) - Sets the interval time....
Starred by 54 users
Forked by 18 users
Languages   C++
Find elsewhere
🌐
PJRC
pjrc.com › teensy › td_timing_IntervalTimer.html
Delay and Timing Functions
Libraries known to use an IntervalTimer include DmxSimple, Adafruit_VS1053, NewPing, FreqCount, RadioHead (only some uses), ShiftPWM, SoftPWM, Talkie, VirtualWire, MsTimer2 & FlexiTimer2. For Teensy 2.0 and Teensy++ 2.0, the TimerOne & TimerThree and FlexiTimer2 libraries provide similar capability.
🌐
Arduino
playground.arduino.cc › Code › SimpleTimer
Arduino Playground - SimpleTimer Library
October 2, 2019 - Copy-n-paste the example code (see below) to get you started with the library. #include <SimpleTimer.h> // the timer object SimpleTimer timer; // a function to be executed periodically void repeatMe() { Serial.print("Uptime (s): "); Serial.println(millis() / 1000); } void setup() { Serial.begin(9600); timer.setInterval(1000, repeatMe); } void loop() { timer.run(); }
🌐
Draeger IT
draeger-it.blog › startseite › interval execution made easy: timer for arduino
Interval execution made easy: Timer for Arduino - draeger-it.blog
You can download it in version 3.0.0 from https://www.arduino.cc/reference/en/libraries/arduino-timer/ as a ZIP file.
Published   January 8, 2026
🌐
Arduino Libraries
arduinolibraries.info › libraries › every-timer
EveryTimer - Arduino Libraries
March 9, 2025 - A library providing the possibility to call a function at specific time intervals.
🌐
Readthedocs
png-arduino-framework.readthedocs.io › timer.html
Arduino Timer — .PNG Arduino Framework 1.0 documentation
Using Timer Object – interval and singleshot callback – in Arduino · Include the library · #include "Timer.h" Create a new Timer object · Timer *timer1 = new Timer(6000); //timer with 6 seconds · Add the following methods in void setup() timer1->setOnTimer(&FunctionCallback); timer1->Start(); //start the thread.
🌐
GitHub
github.com › alextaujenis › RBD_Timer
GitHub - alextaujenis/RBD_Timer: Arduino Timer Library - Manage many timed events without delay or interrupts.
Arduino Timer Library - Manage many timed events without delay or interrupts. - alextaujenis/RBD_Timer
Starred by 46 users
Forked by 19 users
Languages   C++ 100.0% | C++ 100.0%
🌐
Arduino
docs.arduino.cc › libraries › timerinterrupt
TimerInterrupt | Arduino Documentation
December 4, 2022 - This library enables you to use Interrupt from Hardware Timers on an Arduino, Adafruit or Sparkfun AVR board, such as Nano, UNO, Mega, Leonardo, YUN, Teensy, Feather_32u4, Feather_328P, Pro Micro, etc. It now supports 16 ISR-based timers, while consuming only 1 Hardware Timer.
🌐
Scruss
scruss.com › blog › 2017 › 04 › 01 › simple-like-really-simple-arduino-periodic-timer-with-bretts-millistimer-library
Simple — like, really simple — Arduino periodic timer with Brett’s MillisTimer library
April 1, 2017 - // MillisTimerBlink - blink LED ... Libraries … to install) // scruss - 2017-04-01 #include <MillisTimer.h> MillisTimer timer1; // new empty timer object const int led_pin = LED_BUILTIN; // use the built-in LED void ...
🌐
DeepBlue
deepbluembedded.com › home › blog › arduino-timer library & examples
Arduino-Timer Library & Examples
August 17, 2023 - The main function in the Arduino-Timer library is called .tick() and you must call it in the main super loop() while the microcontroller is IDLE to advance the tick count and dispatch the tasks when their periodicity time is due.
🌐
GitHub
github.com › loglow › IntervalTimer
GitHub - loglow/IntervalTimer: Timer library for Teensy 3.0
Timer library for Teensy 3.0. Contribute to loglow/IntervalTimer development by creating an account on GitHub.
Starred by 21 users
Forked by 8 users
Languages   C++ 90.1% | C++ 90.1%
🌐
Schaerens
schaerens.ch › iot-arduino-timer-library
Arduino – Libarary: arduino-timer – Peter Schärens Blog
March 10, 2022 - #include "Arduino.h" #include "arduino-timer.h" const int greenLedPin = 10; // green LED const int redLedPin = 13; // red LED const int buttonPin = 2; // button // Delay to be used to debounce button [ms] unsigned long debouncingTime = 100; // timer is a 'software timer'. <2> indicates that up to 2 instances may be used concurrently. // One interval timer is used for green LED and one single-shot timer is used for red LED.
🌐
Arduino Forum
forum.arduino.cc › development tools › ide 1.x
using Teensy IntervalTimer library with Arduino - IDE 1.x - Arduino Forum
September 25, 2017 - Hi, looking around in the forum I found a postage about IntervalTimer in a Teensy comment. There is a description of the methods of the IntervalTimer object which seemed to be suitable for my project. I tested it with a Board setting for a Teensy 3.2 and it worked without including a library.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Interval timer on Arduino: Doubt about TimerOne library - Programming - Arduino Forum
February 15, 2022 - I want to synchronize a timer interrupt from a button is pressed. I want to read a button state 3 seconds later from the first pulse moment (to identify long pressed button, 3 seconds for this example). I'm trying to do with this code: #include #define pinButton 3 #define POWER_ON_TIME 3 //Long press in seconds volatile unsigned long pressed_Time = 0; volatile unsigned long myTime_button = 0; volatile unsigned long myTimeOn_button = 0; volatile unsigned long myTime_pressed = 0; u...