PWM fade 3 leds on Attiny85

Hi there!

I have an ATTiny85 project where I want to fade 3 LED channels. Unfortunately the ATTiny supports only PWM on PB0 and PB1 out of the box.

I read somewhere that it is possible to get PB4 to PWM too with some wizardery but I do not find any ressources to do so.

Any hints to get PWM on PB4 on an ATTiny85?

Thanks in advance!

Software PWM?

The SoftPWM library is not supported on the ATTiny it seems.

I wasn’t suggesting using a library.

As always, you have failed to explain your project in its entirety.

How easy it is to perform software PWM depends critically on what other things you propose to do at the same time. As AWOL points out, not everything is done with a library and libraries frequently do not suit.

I see.

The project is very simple:
Fade 3 leds connected to an ATTiny85; a plus would be to offset the fading a little bit so its not that robotic. Nothing more.

So to implement software PWM by myself I just toggle a pin high / low for a few microseconds in a specific frequency I suspect?!

Thanks!

A little bit more involved.

Get back to you later on this. :grinning:

So to implement software PWM by myself I just toggle a pin high / low for a few microseconds in a specific frequency I suspect?!

To make PWM change the brightness you have to change the ratio between the on and off time.

Arduino does not support attiny85 "out of the box". You have to install a "core" to enable that. For attiny85 there is a choice of cores and some are better than others.

Many older Arduino tutorials use David A Mellis' core, which only supports pwm on two pins.

Spence Konde's (aka Drazzy, forum member) tiny core supports pwm on 3 pins (PB0, PB1, PB4)for tiny85.

As well as checking if a core has the features you need, another way to decide between cores is to check if it is still actively supported by the author, using the date that the last "commit" (code update) was made on GitHub.

For example:

Latest commit by damellis about 3 years ago

compared with:

Latest commit by SpenceKonde 6 days ago

Thank you very much.
I have the Mellis core installed and PB4 didnt respond to analogWrite() how it is expected.

I will try the SpenceKondes core and see how things are going.

Thank you very much for your help!