Go Down

Topic: need a longer rgb fade (Read 630 times) previous topic - next topic

trellsbells2

here is my code:
i cannot figure out for the life of me make it fade over all the colors slowly over an hour. than repeat and so on.
Code: [Select]
// attiny85 RGB led rainbow fade

const int redPin = 1; 
const int grnPin = 2; 
const int bluPin = 0;


void setup()
{
  pinMode(redPin, OUTPUT);     
  pinMode(grnPin, OUTPUT);     
  pinMode(bluPin, OUTPUT);     
}

void loop()
{
redtoyellow();
yellowtogreen();
delay(0);
greentocyan();
cyantoblue();
delay(0);
bluetomajenta();
majenatored();
delay(0);
}


void redtoyellow()
{
   digitalWrite(redPin, HIGH);
   digitalWrite(bluPin, LOW);

  // fade up green
  for(byte i=1; i<100; i++) {
    byte on  = i;
    byte off = 100-on;
    for( byte a=0; a<100; a++ ) {
      digitalWrite(grnPin, HIGH);
      delayMicroseconds(on);
      digitalWrite(grnPin, LOW);
      delayMicroseconds(off);
    }
  }
}



void yellowtogreen()
{
   digitalWrite(grnPin, HIGH);
   digitalWrite(bluPin, LOW);

  // fade down red
  for(byte i=1; i<100; i++) {
    byte on  = 100-i;
    byte off = i;
    for( byte a=0; a<100; a++ ) {
      digitalWrite(redPin, HIGH);
      delayMicroseconds(on);
      digitalWrite(redPin, LOW);
      delayMicroseconds(off);
    }
  }
}


void greentocyan()
{
   digitalWrite(grnPin, HIGH);
   digitalWrite(redPin, LOW);

  // fade up blue
  for(byte i=1; i<100; i++) {
    byte on  = i;
    byte off = 100-on;
    for( byte a=0; a<100; a++ ) {
      digitalWrite(bluPin, HIGH);
      delayMicroseconds(on);
      digitalWrite(bluPin, LOW);
      delayMicroseconds(off);
    }
  }
}



void cyantoblue()
{
   digitalWrite(bluPin, HIGH);
   digitalWrite(redPin, LOW);

  // fade down green
  for(byte i=1; i<100; i++) {
    byte on  = 100-i;
    byte off = i;
    for( byte a=0; a<100; a++ ) {
      digitalWrite(grnPin, HIGH);
      delayMicroseconds(on);
      digitalWrite(grnPin, LOW);
      delayMicroseconds(off);
    }
  }
}


void bluetomajenta()
{
   digitalWrite(bluPin, HIGH);
   digitalWrite(grnPin, LOW);

  // fade up red
  for(byte i=1; i<100; i++) {
    byte on  = i;
    byte off = 100-on;
    for( byte a=0; a<100; a++ ) {
      digitalWrite(redPin, HIGH);
      delayMicroseconds(on);
      digitalWrite(redPin, LOW);
      delayMicroseconds(off);
    }
  }
}



void majenatored()
{
   digitalWrite(redPin, HIGH);
   digitalWrite(grnPin, LOW);

  // fade down blue
  for(byte i=1; i<100; i++) {
    byte on  = 100-i;
    byte off = i;
    for( byte a=0; a<100; a++ ) {
      digitalWrite(bluPin, HIGH);
      delayMicroseconds(on);
      digitalWrite(bluPin, LOW);
      delayMicroseconds(off);
    }
  }
}

mckennie

why are you using such a complicated pwm method? why not just use the built in analogwrite function?
EDIT: are you using an attiny85?

PaulS

Code: [Select]
delay(0);
delay(0);
delay(0);

Why?

What does your code do now? How long does it take to cycle through the color range?

trellsbells2

yah its for an attiny85.. also about the delay(0) I left it there because I did have a delay before but I took it away. And If i wanted it back then I would like to add it quickly instead of right the couple of lines of code again lol

dhenry

Quote
i cannot figure out for the life of me make it fade over all the colors slowly over an hour.


Rather than repeat it 100x, repeat it 1000x, or 10000x, etc. until you are happy.

Riva

Here is a sketch I wrote to create a colour cycling mood lamp using an ATmega85. Just alter mainDelay to adjust the loop time. The result is here http://arduino.cc/forum/index.php/topic,134827.0.html with a fast cycle time to reduce video length  :)
http://forum.arduino.cc/index.php?action=unread;boards=5,67,10,11,66,12,15,17,21,22,23,24,25,29;ALL

Go Up