Faking software PWM on ATTiny84?

I needed 6 pins, and since my prefered chip ATMega328, 168, and 88 in TQFP-32 packages are all out of stock on 2 of my favorite part sites I am using ATTiny84 as the next alternative since I do have SOIC-16 versions on hand.

void loop() {
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 5; j++) {
      analogWrite(LED[j], (random(255));
    }
    delay(500);
  }
  // do something else after loop of 100 is done
}

This was originally how I planned, the 6 outputs would be set in LED[ x ] array to use the 6 PWM pins. ATtiny84 has only 2 PWM pins and some of the info I found via Google involves manually hammering the pin's output with short delay between high and low to simulate duty %. This won't work if I am trying to randomly set 6 LEDs brightness, changing every half second. Is there a software PWM library that will work with ATTiny or an alternate PWM trick? The other alternative is to use my Mega2560 which does have many PWM pins but it seems silly to use a big Arduino board for just 6 LEDs.

Yep, use a 74HC595 and use software PWM...
I've run 24 RGB LEDs that way (72 channels) at 4MHz.

And you learn something new !

I think it has 4 pwm pins:

Which core are you using? I would recommend this one:

I don't see why that would not work.

Consider using ws2812 or apa106 LEDs. Then you could even use attiny85 to drive them.

Apart from ATTiny84 having 14 pins not 16, what relevance does it have to PWM output? Just curious why you mentioned it

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