Instructables
Picture of Arduino RGB LED Christmas Wreath


This is my first instructable.  Have been a long time lurker and tinkerer.  This year I decided to make a RGB LED Christmas wreath with some cool led patterns.  I decided to use an Arduino Uno microcontroller that I had laying around.  When looking at controlling the RGB LEDs, I found that I needed 3 PWM pins per channel of LEDs.  I found that with the Uno, I could only have 2 channels of LEDs due to only having 6 PWM pins total.  From another project, I already had 7 common cathode RGB LEDs laying around, so I assigned 4 to the main channel, and 3 to the other channel.


Materials Required:

Wreath
Arduino Uno/compatible with 6 PWM pins
at least a few RGB LEDs, Common Cathode
5' Cat5e or similar 8 conductor wire
Dolphin clips crimpable wire connectors (not really necessary)
Soldering iron & solder
Break Away Headers - Long (PRT-1015 from Sparkfun)
9v battery clip (with header, or solder one to the wires)
SPST switch for power (optional, I actually used SPDT)
Hot glue gun
Zipties

 
Remove these adsRemove these ads by Signing Up

Step 1: Breadboard first

Picture of Breadboard first
So I took to the breadboard and assembled all the RGB LEDs on there for testing.  Using 2 channels (3 leds in series for one channel, 4 leds in series for another channel), with a common ground from the arduino, I wanted to make some cool patterns.  I found some code @ http://forum.arduino.cc/index.php/topic,11293.0.html and it worked, so I started modifying it and came up with some different types of patterns.

Basically, just put 2 LEDs on the breadboard.  The pinout for the LEDs I used were Short-Long-Med-Short = Red-Ground-Green-Blue.  Connect the grounds together and to the GND pin on the arduino using jumper wire.  The PWM pins you have to use on the arduino are 3,5,6, and 9,10,11.  Connect LED1 red to 3, LED1 green to 5, LED1 Blue to 6.  Then LED2 Red to 9, LED2 Green to 10, LED2 Blue to 11.  I didn't use any resistors in this circuit because these LEDs are pretty solid and I haven't had one burn up yet.  You could put a 200-300 ohm resistor in front of each pin but I didn't have any low impedance resistors at the time.  It only has to work for a month out of every year! =]

Sorry my breadboard picture is so bad, I only got a cellphone camera video and the quality was not great.

Here is the most important part of it all: the code.


/*
*
* ARDUINO RGBLED XMAS WREATH 2013
* by amplex (alexdatsko@gmail.com)  12-6-13
*
* This project consists of an Arduino Uno (R3, doesn't matter).  You just need 6 PWM pins to be able to control the RGB LEDs.  I know, I should have put some resistors in but I bench tested it for hours and nothing burned out.
* This project uses 2 channels of RGB LEDS (https://www.sparkfun.com/products/9853 I used common cathode, pinout is Red,Ground,Green,Blue (see below) ) cycles between different patterns for an xmas wreath
* Enjoy the Blinkenlights!
*
* some code stolen from ( http://forum.arduino.cc/index.php/topic,11293.0.html ) and ( http://www.instructables.com/id/RGB-LED-transition-Arduino/ )
* and got heavily modified, made a bunch of new patterns, etc.  the fun part.  there was some debugging that got annoying so I just commented out those routines.  After the program looped once completely, they would hang after 2 iterations (cycles).. Not sure why.
* Feel free to figure it out and clue me in.  Tried checking memory, removing new subroutine variables and constants, tried another arduino, same issue.  Not all code standardized or pretty by any means..
*
*
* ARDUINO PINOUT, TO CAT5E COLORS
* -------------------------------
* pin 3  - Red     -  ORANGE
* pin 5  - Green   -  GREEN
* pin 6  - Blue    -  BLUE
* pin 9  - Red     -  WHITE/ORANGE
* pin 10 - Green   -  WHITE/GREEN
* pin 11 - Blue    -  WHITE/BLUE
* ground - Brown   -  BROWN
* (UNUSED)         -  WHITE/BROWN
*
*       RGB LED PINOUT
*       --------------
*               _
*              ( )
*              /~\
*             /| |\
*            / | | \
*            | | | |
*            | | | |
*            | | | |
*              | | BL
*           RED| GR 
*             GND
*
*
*   LED Colors used on Cat5e cable
*   ------------------------------
* 1 BL OR GR       - BRN-Ground
* 2 w/BL w/OR w/GR - BRN-Ground
* 3 BL OR GR       - BRN-Ground
* 4 w/BL w/OR w/GR - BRN-Ground
* 5 BL OR GR       - BRN-Ground
* 6 w/BL w/OR w/GR - BRN-Ground
* 7 BL OR GR       - BRN-Ground
*

*/


// set analog pins

#define LED1 3
#define LED2 5
#define LED3 6
#define LED4 9
#define LED5 10
#define LED6 11

#define PLASMADELAY 4 
#define VERYQUICKDELAY 10
#define QUICKDELAY 30
#define LONGDELAY 100

#define fade(x,y) if (x>y) x--; else if (x<y) x++;

int redNow = random(255);
int blueNow = random(255);
int greenNow = random(255);
int redNew = redNow;
int blueNew = blueNow;
int greenNew = greenNow;


float RGB1[3];
float RGB2[3];
float RGB3[3];
float RGB4[3];
float INC[3];
float INC2[3];

int red, green, blue;
int red2, green2, blue2;

int pause=10;
int up=1;
int cycles=2;
int x=0;
int y=0;
int xx=0;


void setup()     //  **************************** SETUP *********************************
{
  Serial.begin(9600);
  randomSeed(analogRead(0));
 
 
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
 
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);

  for (x=0; x<3; x++)
  {
    RGB1[x] = random(256);
    RGB2[x] = random(256);
    RGB3[x] = random(256);
    RGB4[x] = random(256);
  }

  showfreeram();  // check RAM left, my Serial strings seem to take a lot of memory, causing lockups once in awhile for some reason.

  RGBtest();   // Test both RGB LED Channels.  Test LED 1 Red, then green, then blue, then LED 2 Red, Green, Blue

  randomSeed(analogRead(0));
}

void dopause() {
    delay(pause);  
    if (up==1) pause=pause+10;
    if (up==0) pause=pause-10;
    if (pause>=200) up=0;  // reset timer, timing is now going down
    if (pause<=0) up=1;  // timing is going back up
}

void dopause2() {
    delayMicroseconds(pause*10);  
    if (up==1) pause=pause+10;
    if (up==0) pause=pause-10;
    if (pause>=200) up=0;  // reset timer, timing is now going down
    if (pause<=0) up=1;  // timing is going back up
}

void domicropause() {
//  delay(VERYQUICKDELAY*pause);
    delayMicroseconds(pause*10);  
    if (up==1) pause=pause+1;
    if (up==0) pause=pause-1;
    if (pause>=20) up=0;  // reset timer, timing is now going down
    if (pause<=0) up=1;  // timing is going back up
}

void LEDwrite(int led, int red, int green, int blue) {
  if (led==1) {
      analogWrite (LED1, red); 
      analogWrite (LED2, green);  
      analogWrite (LED3, blue);    
  } else
  if (led==2) {
      analogWrite (LED4, red); 
      analogWrite (LED5, green);  
      analogWrite (LED6, blue);  
  }

//      delay(VERYQUICKDELAY);  
}


void LEDplasmawrite(int led, int red, int green, int blue) {
  if (led==1) {
      analogWrite (LED1, red); 
      analogWrite (LED2, green);  
      analogWrite (LED3, blue);    
  } else
  if (led==2) {
      analogWrite (LED4, red); 
      analogWrite (LED5, green);  
      analogWrite (LED6, blue);  
  }

      delay(PLASMADELAY);   // VERYQUICK DELAY IS TOO SLOW
}

void randomjumpfade() {    // &&&&&&&&&&&&&&&&&&&&&&&&& RANDOM JUMP FADE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nRandomJumpFade..\n");

  for (y=0; y<cycles; y++) {
    Serial.print(y);
    Serial.print("..");
    for (x=0; x<3; x++) {
      INC[x] = (RGB1[x] - RGB2[x]) / 256;
      INC2[x] = (RGB3[x] - RGB4[x]) / 256;
    }
    for (x=0; x<256; x++) {
      red = int(RGB1[0]);
      green = int(RGB1[1]);
      blue = int(RGB1[2]);

      red2 = int(RGB3[0]);
      green2 = int(RGB3[1]);
      blue2 = int(RGB3[2]);

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
 
      for (xx=0; xx<3; xx++) {
         RGB1[xx] -= INC[xx];
         RGB3[xx] -= INC2[xx];   // INC[xx] for 'different' jumps
      }
      delay(QUICKDELAY);   // dont need to wait 1000.. make it smoother 
    }
    for (x=0; x<3; x++) {
      RGB2[x] = random(956)-700;
      RGB2[x] = constrain(RGB2[x], 0, 255);
      RGB4[x] = random(1856)-1600;
      RGB4[x] = constrain(RGB4[x], 0, 255);
    }
  } // end y<cycles
}

void slowfadeinwhite() {    // &&&&&&&&&&&&&&&&&&&&&&&&& SLOW FADE-IN 'BLINK' &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nSlowFadeinWhite..\n");
    for (x=0; x<256; x++) {

      red = x;
      green = x;
      blue = x;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);

      delay(VERYQUICKDELAY);
    } //end x<256
   
  for (y=0; y<cycles; y++) {
    Serial.print(y);
    Serial.print("..");

    for (x=0; x<256; x++) {
      red = 255-x;
      green = 255-x;
      blue = 255-x;

      red2 = x;
      green2 = x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);

    delay(VERYQUICKDELAY);      

    } //end x<256

    // BLINK  ***** switch states   

    for (x=0; x<256; x++) {
      red = x;
      green = x;
      blue = x;

      red2 = 255-x;
      green2 = 255-x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);

      delay(VERYQUICKDELAY);
    } //end x<256
   
  }  // end y<cycles

}

void fastblink() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST BLINK &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("Fastblink..\n");
 
  for (y=0; y<cycles*16; y++) {
// serial buffer being overrun?
//      Serial.print(y);
//      Serial.print("..");
 
      red = 222;
      green = 222;
      blue = 222;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause();  

    // BLINK

      LEDwrite(1,red2,green2,blue2);
      LEDwrite(2,red,green,blue);
      dopause();

   
  }  // end y<cycles
}

void fastblinkcolorfade() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST BLINK COLOR FADE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nFastblink Colorfade..\n");
 
  for (y=0; y<cycles*4; y++) {
    Serial.print(y);
    Serial.print("..");
 
    for (x=0; x<256; x++) {

      red = x;
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;


      red2 = x;
      green2 = 255-x;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause();   
    } //end x<256
   
    //  &&&&&&&&&&&&&&&&&&&&&&&&&&&& 2
   
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 255-x;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256
   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;


      red2 = 0;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
     
    } //end x<256

    //  &&&&&&&&&&&&&&&&&&&&&&&&&&&& 3
   
    for (x=0; x<256; x++) {

      red = 255-x;
      green = 0;
      blue = x;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256
   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;


      red2 = 255-x;
      green2 = 0;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
     
    } //end x<256
  
  }  // end y<cycles
}

void fastblinkcolorfademod() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST BLINK COLOR FADE MODIFIED .. &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nFastblink Colorfade Modified..\n");
 
  for (y=0; y<cycles*4; y++) {
    Serial.print(y);
    Serial.print("..");
 
    for (x=0; x<256; x++) {

      red = x;
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 255-x;


      red2 = x;
      green2 = 255-x;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause();   
    } //end x<256
   
    //  &&&&&&&&&&&&&&&&&&&&&&&&&&&& 2
   
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 255-x;

      red2 = 255-x;
      green2 = 0;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256
   
    // BLINK
    for (x=0; x<256; x++) {

      red = 255-x;
      green = 0;
      blue = x;


      red2 = 0;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
     
    } //end x<256

    //  &&&&&&&&&&&&&&&&&&&&&&&&&&&& 3
   
    for (x=0; x<256; x++) {

      red = 255-x;
      green = 0;
      blue = x;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
    } //end x<256
   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 255-x;


      red2 = 255-x;
      green2 = 0;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
     
    } //end x<256
  
  }  // end y<cycles
}

void fastblinkswap() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST BLINK COLOR swap .. &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("Fastblink color swap..\n");
 
  for (y=0; y<cycles; y++) {
    Serial.print(y);
    Serial.print("..");

    Serial.print("(1),");
    for (x=0; x<256; x++) {

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256
    for (x=255; x>0; x--) {

      red = x;
      green = 255-x;
      blue = x;

      red2 = x;
      green2 = x;
      blue2 = 255-x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,green,red);
      LEDwrite(2,blue2,green2,red2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 
    } //end x<256

    Serial.print("(2),");
    // ********************************** 2
  
    for (x=0; x<256; x++) {

      red = 255-x;
      green = x;
      blue = x;

      red2 = x;
      green2 = 255-x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,green,red);
      LEDwrite(2,blue2,green2,red2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256
    for (x=255; x>0; x--) {

      red = 255-x;
      green = x;
      blue = x;

      red2 = x;
      green2 = 255-x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,red,green);
      LEDwrite(2,blue2,red2,green2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256

    Serial.print("(3),");
    // ********************************** 3
  
    for (x=0; x<256; x++) {

      red = x;
      green = x;
      blue = 255-x;

      red2 = 255-x;
      green2 = x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,green,red);
      LEDwrite(2,blue2,green2,red2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256
    for (x=255; x>0; x--) {

      red = x;
      green = x;
      blue = 255-x;

      red2 = 255-x;
      green2 = x;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

      LEDwrite(1,blue,green,red);
      LEDwrite(2,blue2,green2,red2);
      domicropause(); 
      LEDwrite(1,0,0,0);
      LEDwrite(2,0,0,0);
      domicropause(); 

    } //end x<256

  }
}


void fastRGBblink() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST COLOR BLINK &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nfastRGBblink..\n");
 
  for (y=0; y<cycles*4; y++) {
    Serial.print(y);
    Serial.print("..");


  // **** 1 *********************************************************   LED1 = RED, LED2 = GREEN
    Serial.print("1,");
    for (x=0; x<256; x++) {

      red = x;
      green = 0;
      blue = 0;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();

    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;


      red2 = 0;
      green2 = x;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();
 
    }  //end x<256


  // **** 2 ********************************************************* LED1 = GREEN, LED2 = BLUE
 
    Serial.print("2,");
    for (x=0; x<256; x++) {

      red = 0;
      green = x;
      blue = 0;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();
    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;

      red2 = 0;
      green2 = 0;
      blue2 = x;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();
    }  //end x<256

   
  // **** 3 ********************************************************* LED1 = BLUE, LED2 = RED
 
    Serial.print("3, ");
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = x;

      red2 = 0;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2();
    } //end x<256

   
    // BLINK
    for (x=0; x<256; x++) {

      red = 0;
      green = 0;
      blue = 0;

      red2 = x;
      green2 = 0;
      blue2 = 0;

      LEDwrite(1,red,green,blue);
      LEDwrite(2,red2,green2,blue2);
      dopause2(); 
    } //end x<256

   
  }  // end y<cycles
}




void fastcolorfade() {    // &&&&&&&&&&&&&&&&&&&&&&&&& FAST COLOR FADE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

  Serial.print("\nFastcolorFade..\n");
 
  for (y=0; y<cycles; y++) {
    Serial.print(y);
    Serial.print("..");

// **************** fadein red (1)
  Serial.print("fadein red..");
    for (x=0; x<256; x++) {
      red = x;                             // RED IN, GREEN OUT, BLUE OFF
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

    for (x=255; x>0; x--) {
      red = x;                            // RED OUT, GREEN IN, BLUE OFF
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

// **************** fadein green (2)
  Serial.print("fadein green..");

    for (x=0; x<256; x++) {
      red = 0;                           // RED OFF, GREEN OUT, BLUE IN
      green = 255-x;
      blue = x;

      red2 = x;
      green2 = 0;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

    for (x=255; x>0; x--) {
      red = 0;                           // RED OFF, GREEN IN, BLUE OUT
      green = 255-x;
      blue = x;

      red2 = x;
      green2 = 0;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

// **************** fadein blue (3)
  Serial.print("fadein blue..");
    for (x=0; x<256; x++) {
      red = x;                           // RED IN, GREEN OUT, BLUE OFF
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

    for (x=255; x>0; x--) {
      red = x;                         
      green = 255-x;
      blue = 0;

      red2 = 0;
      green2 = x;
      blue2 = 255-x;
     
      LEDplasmawrite(1,red,green,blue);
      LEDplasmawrite(2,red2,green2,blue2);
    } //end x<256

   
    Serial.print("\n");
  } // end y<cycles*16
}

int freeRam ()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

void showfreeram() {
  Serial.print( "\nFree RAM = " );
  Serial.println( freeRam() );
}

void randomfadeslow()
{
  Serial.print("\nRandomfadeSlow..\n");

  for (y=0; y<cycles*4; y++) {
    Serial.print(y);
    Serial.print("..");
    LEDwrite(1,redNow,greenNow,blueNow);
    LEDwrite(2,redNow,greenNow,blueNow);
    redNew = random(255);
    greenNew = random(255);
    blueNew = random(255);
    // fade to new colors
    while (( redNow   != redNew   )  ||
           ( greenNow != greenNew )  ||
           ( blueNow  != blueNew  ))
    {
      fade(redNow,redNew)
      fade(greenNow,greenNew)
      fade(blueNow,blueNew)
      LEDwrite(1,redNow,greenNow,blueNow);
      LEDwrite(2,redNow,greenNow,blueNow);
      delay(QUICKDELAY);
    }
  } //end y<cycles
}

void RGBtest() {
  LEDwrite(1,0,0,0);
  LEDwrite(2,0,0,0);
  for (y=0; y<cycles; y++) {
//test LED channel 1
      LEDwrite(1,255,0,0);
      delay(LONGDELAY*4);
      LEDwrite(1,0,255,0);
      delay(LONGDELAY*4);
      LEDwrite(1,0,0,255);
      delay(LONGDELAY*4);
      LEDwrite(1,0,0,0);
      delay(LONGDELAY*4);

//test LED channel 2
      LEDwrite(2,255,0,0);
      delay(LONGDELAY*4);
      LEDwrite(2,0,255,0);
      delay(LONGDELAY*4);
      LEDwrite(2,0,0,255);
      delay(LONGDELAY*4);
      LEDwrite(2,0,0,0);
      delay(LONGDELAY*4);
  }
}


void loop() {    //  **************************** MAIN *********************************

/*

// THESE WERE CAUSING LOCKUPS WHEN THEY ITERATE TWICE FOR SOME REASON..

  fastblinkswap();

  fastblink();
  showfreeram();
*/


 
  randomSeed(analogRead(0));

  randomfadeslow();
  showfreeram();
 
  fastRGBblink();
  showfreeram();

  slowfadeinwhite();
  showfreeram();
 
  fastblinkcolorfade();
  showfreeram();

  fastblinkcolorfademod();
  showfreeram();
 
  randomjumpfade(); 
  showfreeram(); 

  fastcolorfade();
  showfreeram();

}


audreyobscura8 months ago
It's beautiful! Do you think you could provide a link to which RGB LEDs you used? I have tried to use some, and have had varying luck with them.
amplex (author)  audreyobscura8 months ago
Thanks! I ordered these from Sparkfun: https://www.sparkfun.com/products/9853
Be careful because the pinout is different on one of the pages, the Ground is the longest pin.