I have modified TimerOne library in order to support ATTiny85. Check it out!

Hi Guys,

I have modified Paul Stoffregen's TimerOne library. I have added support for ATTiny85 except for the PWM functionality. The PWM functionality is still not implemented for ATTiny85.
I have done this modification of the original TimerOne library because I had to use ATTiny85's Timer1 in a convenient way for my project. Unfortunately I could not find a library for Timer1 that supports this microcontroller. Therefore I have written the functionality myself as an addition to the already popular TimerOne library. I did not implemented the PWM functionality though because I do not use that in my project and I did not have the time to invest on this topic as well.
While working on this library I have found out that ATTiny85's Timer1 is unique compared to any other Atmel microcontroller. It has unique features like achieving 64 MHz PWM via PLL, high resolution of Timer1 (although Timer1 is only 8 bit the high resolution is achieved through many prescalers available for this Timer). It is also interesting to note that Timer0 and Timer1 share the same register for timer interrupts - TIMSK therefore you can not just set this register to 0 when you detach an interrupt as it is being done in the detachInterrupt() method for Arduino but instead you have to only unset the exact bit responsible for the current timer (Timer1 in this case).
I have added an example for ATTiny85 in the folder /examples. This library can be used directly without any modifications to your existing code in case you are porting your code from Arduino to ATTiny85 except if you use the PWM functionality. When using this library please bear in mind that the maximum time period achievable with Timer1 on ATTiny85 is ~ half a second. Of course I am saying "maximum" here in the context of the TimerOne library. Otherwise if you need to achieve longer time period you can simply execute a custom sub-method in your custom method that is called on each interrupt. For example you can execute your custom sub-method every 4-th time when your custom method is called on each interrupt and that way you will expand the time 4 times (if you have set the timer to 500000 microseconds period through this approach you will achieve 4 x 0.5 seconds = 2 seconds). And last but not least - make sure that no other library in your code is using Timer1 when using the current TimerOne library with ATTiny85. millis() and micros() will be working with this library since they use Timer0 in the latest ATTinyCore's. Nevertheless if for some reason you need to use an older core for Attiny85 that uses Timer1 for millis() and micros() then you will have to change the value of TIMER_TO_USE_FOR_MILLIS variable of your core(it is located in "core_build_options.h" in older cores).

I will be glad if I have saved some time to someone like me who needs to use Timer1 of the ATTiny85 microcontroller in a convenient way!

Here is the link to my repository in GitHub:

and here is the direct link for download of my modified version of TimerOne library that adds support for ATTiny85:


Please check it out and enjoy!

Best Regards,
Stoyko Dimitrov

Had an issue migrating a project from the Nano to the ATTiny85

Your modification seems to work beautifully....

Thanks !