Simple RGB LED fading without using analogWrite

Hello,

I am trying to get an RGB fade going with an ATtiny85. The problem is that every fading function I have found online so far has used analogWrite, and the ATtiny85 only has two PWM pins: not enough for R, G and B.

I am trying to implement this by using if statements, but it is proving to be quite difficult. I am currently only trying to get this method to work for one color, as I believe it could be easily extended to several once working. I included a picture of the board being used.

This is what I have so far:

void Fade()
{
  for(byte i=1; i<100; i++) 
  {
    greenBrightness0 = greenBrightness0 + greenFadeRate; //updates the brightness with a 1/100th increment 
    byte greenOn  = greenBrightness0 * .390625; //wierd number is factor to go from 256 to 100
    byte greenOff =  100 - greenOn;
    byte a = 0;
    boolean d = false; //to ensure that an if-loop is not entered twice in a row
    while(a < 100) 
    {
      greenTime0 = micros(); //what time is it, mr. wolf?
      if(d == false && (greenTime0 > greenTime3 + greenOn)) //greenTime3 initially = 0
      {
        digitalWrite(greenPin, HIGH);
        greenTime2 = greenTime0; //records the time when greenPin went HIGH
        d = true;
      }
      greenTime1 = micros(); //what time is it, mr. wolf?
      if(d == true && (greenTime1 > greenTime2 + greenOff))
      {
        digitalWrite(greenPin, LOW);
        greenTime3 = greenTime1; //records the time when greenPin went LOW
        d = false;
        a++; //increments while loop
      }
    }
  }
}

I hope this makes sense, and that I am posting in the correct part of the forum.
Thanks!

I hope this makes sense, and that I am posting in the correct part of the forum.

It would help if we knew what the problem was.

ah.

my code doesn't actually work. Any ideas on how I could effectively implement a fade using if-statements?

byte greenOn  = greenBrightness0 * .390625;

What do you expect to see here?
it is a byte not a floating point number so in effect you are multiplying by zero.

The Tiny 85 has 3 PWM capable pins. I am posting from my iPhone just now, so I cannot provide code, but I have successfully done it

Grumpy_Mike:

byte greenOn  = greenBrightness0 * .390625;

What do you expect to see here?
it is a byte not a floating point number so in effect you are multiplying by zero.

oh god. thank you. I will update that. Though doesnt it not actually return zero, as greenBrightness0 * .390625 will give some decimal number, which is then rounded up or down? eg. 55* .390625 = 21.48.... = 21

Here is a link to a Larson scanner that I premiered here last year.
No analogWrites were used.

http://forum.arduino.cc/index.php?PHPSESSID=5p3o29mqvhmcvhnsmu6o7qp043&topic=171567.0

http://forum.arduino.cc/index.php?PHPSESSID=uknjl2gkltbecaopopsnm2snr5&topic=171567.msg1278883#msg1278883
[see attachment static_fading_8.pde]