title: 2 Pin RGB LED on an Arduino
body: <p>I'm having some trouble setting up my RGB led. It's not common anode, so it only has 2 pins. Not 4. I can't seem to set the led up to change color. It will only blink red. I want the led to cycle through colors. Thanks for Helping!</p>
  
  <pre><code>int led1 = 2; //Don't worry about the other led variables, they work
  int led2 = 7;
  int led3 = 9;
  int led4 = 12;
  int led5 = 13;
  int redPin = 5;int greenPin = 4;
  int bluePin = 3;
  
  //#define COMMON_ANODE
  
  void setup(){
    pinMode(led1, OUTPUT);
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);
    pinMode(led2, OUTPUT);
    pinMode(led3, OUTPUT);
    pinMode(led4, OUTPUT);
    pinMode(led5, OUTPUT);
  }
  
  void loop(){
   setColor(0, 255, 0);  // green
    delay(1000);
    setColor(0, 0, 255);  // blue
    delay(1000);
    setColor(255, 255, 0);  // yellow
    delay(1000);  
    setColor(80, 0, 80);  // purple
    delay(1000);
    setColor(0, 255, 255);  // aqua
    delay(1000);
  
  }
  
   void setColor(int red, int green, int blue){
    #ifdef COMMON_ANODE
      red = 255 - red;
      green = 255 - green;
      blue = 255 - blue;
    #endif
    analogWrite(redPin, red);
    analogWrite(greenPin, green);
    analogWrite(bluePin, blue);  
  }
  </code></pre>