Use Timer interrupt on LED

Hi all!

I’m trying to blink an LED at a period of 0.02ms by using Timer3. I’m using Arduino Leonardo, ATmega32u4.

I refer to for learning purpose:

I manage to get the LED to blink using Timer1.

My Code:

#include <TimerOne.h>

void setup()
  pinMode(13, OUTPUT);
  Timer1.initialize(10000);         // initialize timer1, and set a 1/2 second period
  Timer1.pwm(9, 512);                // setup pwm on pin 9, 50% duty cycle
  Timer1.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt

void callback()
  digitalWrite(13, digitalRead(13) ^ 1);

void loop()

But for Timer3, I’m not sure how. I downloaded the and import. I faced the errors:

In file included from c:\users\user\desktop\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,
                 from C:\Users\User\Documents\Arduino\libraries\Timer3\TimerThree.h:14,
                 from C:\Users\User\Documents\Arduino\libraries\Timer3\TimerThree.cpp:15:
C:\Users\User\Documents\Arduino\libraries\Timer3\TimerThree.cpp: In member function 'void TimerThree::pwm(char, int, long int)':
C:\Users\User\Documents\Arduino\libraries\Timer3\TimerThree.cpp:61:30: error: 'PORTE3' was not declared in this scope
   if(pin == 5) { DDRE |= _BV(PORTE3); TCCR3A |= _BV(COM3A1); }
C:\Users\User\Documents\Arduino\libraries\Timer3\TimerThree.cpp:62:30: error: 'PORTE4' was not declared in this scope
   if(pin == 2) { DDRE |= _BV(PORTE4); TCCR3A |= _BV(COM3B1); }
C:\Users\User\Documents\Arduino\libraries\Timer3\TimerThree.cpp:63:30: error: 'PORTE5' was not declared in this scope
   if(pin == 3) { DDRE |= _BV(PORTE5); TCCR3A |= _BV(COM3C1); }
Error compiling.

Does anybody knows how do I use Timer3 for the same purpose of blinking LED?

TimerThree library on the page you linked to the playground is written for and only works with the Arduino Mega.
Replace the library with newer ones from here that work on more ARV's including Leonardo.

They have some simple help info here.

It’s working now! Thanks a million!