Watching for a simple timer library with explain

i want to use two timers in my code like this testing sketch using "Timerinterrupt "library


#define TIMER_INTERRUPT_DEBUG         0
#define _TIMERINTERRUPT_LOGLEVEL_     0

#define USE_TIMER_1     true
#define USE_TIMER_2     true
#define USE_TIMER_3     false
#define USE_TIMER_4     false
#define USE_TIMER_5     false

#include "TimerInterrupt.h"

int Button1 = 0;
int last_Button1 = 0;
int Button2 = 0;
int last_Button2 = 0;

unsigned long interval = 1000;
void setup()
{
  pinMode(4,INPUT_PULLUP);
  pinMode(5,INPUT_PULLUP);
  
  ITimer1.init();
  ITimer1.attachInterruptInterval(interval,Function1);
 
  ITimer2.init();
ITimer2.attachInterruptInterval(interval,Function2);

     ITimer1.start();
     delay(3000);
     ITimer2.start();
}

void Function1 ()  {
  Serial.println(millis());
}
void Function2 ()  {
  Serial.println("Timer2 is active");
}

void loop()
{
  Button1 = digitalRead(4);
  Button2 = digitalRead(5);

  if (Button1 != Last_Button1)
  {
    if (Button1==LOW)  {
    ITimer1.stop();
    }
    Last_Button1 = Button1;
  }
    if (Button2 != Last_Button2)
  {
    if (Button2==LOW)  {
    ITimer2.stop();
    }
    Last_Button2 = Button2 ;  
  }

}


  
}

but am getting error this -------

Arduino: 1.6.8 (Windows 7), Board: "Arduino Leonardo"

WARNING: Spurious .github folder in 'TimerInterrupt' library
WARNING: Category 'Timing,Control,Device,Time,Timer,Interrupt,avr,teensy' in library TimerInterrupt is not valid. Setting to 'Uncategorized'
WARNING: Spurious .github folder in 'TimerInterrupt_Generic' library
WARNING: Category 'Timing, Control, Device, Time, Timer, AVR, Mega-AVR, SAM-DUE, ESP32, ESP8266, SAMD, NRF52, STM32, Teensy, MBED, Nano-33-BLE, interrupt' in library TimerInterrupt_Generic is not valid. Setting to 'Uncategorized'
WARNING: Category 'Timing,Control,Device,Time,Timer,esp32' in library ESP32TimerInterrupt is not valid. Setting to 'Uncategorized'
C:\Users\acer\Documents\Arduino\_16__ISR__TIMERS__TEST\_16__ISR__TIMERS__TEST.ino: In function 'void setup()':

_16__ISR__TIMERS__TEST:27: error: 'ITimer2' was not declared in this scope

   ITimer2.init();

   ^~~~~~~

C:\Users\acer\Documents\Arduino\_16__ISR__TIMERS__TEST\_16__ISR__TIMERS__TEST.ino:27:3: note: suggested alternative: 'ITimer1'

   ITimer2.init();

   ^~~~~~~

   ITimer1

_16__ISR__TIMERS__TEST:30: error: 'class TimerInterrupt' has no member named 'start'

      ITimer1.start();

              ^~~~~

C:\Users\acer\Documents\Arduino\_16__ISR__TIMERS__TEST\_16__ISR__TIMERS__TEST.ino: In function 'void loop()':

_16__ISR__TIMERS__TEST:47: error: 'Last_Button1' was not declared in this scope

   if (Button1 != Last_Button1)

                  ^~~~~~~~~~~~

C:\Users\acer\Documents\Arduino\_16__ISR__TIMERS__TEST\_16__ISR__TIMERS__TEST.ino:47:18: note: suggested alternative: 'last_Button1'

   if (Button1 != Last_Button1)

                  ^~~~~~~~~~~~

                  last_Button1

_16__ISR__TIMERS__TEST:50: error: 'class TimerInterrupt' has no member named 'stop'

     ITimer1.stop();

             ^~~~

_16__ISR__TIMERS__TEST:54: error: 'Last_Button2' was not declared in this scope

     if (Button2 != Last_Button2)

                    ^~~~~~~~~~~~

C:\Users\acer\Documents\Arduino\_16__ISR__TIMERS__TEST\_16__ISR__TIMERS__TEST.ino:54:20: note: suggested alternative: 'last_Button2'

     if (Button2 != Last_Button2)

                    ^~~~~~~~~~~~

                    last_Button2

_16__ISR__TIMERS__TEST:57: error: 'class TimerInterrupt' has no member named 'stop'

     ITimer1.stop();

             ^~~~

C:\Users\acer\Documents\Arduino\_16__ISR__TIMERS__TEST\_16__ISR__TIMERS__TEST.ino: At global scope:

_16__ISR__TIMERS__TEST:66: error: expected declaration before '}' token

 }

 ^

exit status 1
'ITimer2' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

examples from library i could not understad.
is there a link for two Timers in one library with simply explain for use by Arduino 32u4 boards

which is explained like as Timer one
inwhich both timers can be simply initial , start and stop etc. like bleow

#include  "library_name.h"
  
  ITimer1.init();
  ITimer1.attachInterruptInterval(interval,Function1);
 
  ITimer2.init();
ITimer2.attachInterruptInterval(interval,Function2);

     ITimer1.start();

     ITimer2.start();


    ITimer1.stop();

    ITimer2.stop();

Check out my tutorial How to write Timers and Delays in Arduino which starts at the basics and builds to a simple millisDelay timer class with multiple examples.

You don’t need HW timers and interrupts for such a task. And don’t use Serial.print in an interrupt routine. It can block your whole sketch.

if you don’t want to bother with millis() directly, you can use the MoToTimer class of the MobaTools library .

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.