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!