/* SparkFun Inventor's Kit Example sketch 03 RGB LED Make an RGB LED display a rainbow of colors! Hardware connections: An RGB LED is actually three LEDs (red, green, and blue) in one package. When you run them at different brightnesses, the red, green and blue mix to form new colors. Starting at the flattened edge of the flange on the LED, the pins are ordered RED, COMMON, GREEN, BLUE. Connect RED to a 330 Ohm resistor. Connect the other end of the resistor to Arduino digital pin 9. Connect COMMON pin to GND. Connect GREEN to a 330 Ohm resistor. Connect the other end of the resistor to Arduino digital pin 10. Connect BLUE to a 330 Ohm resistor. Connect the other end of the resistor to Arduino digital pin 11. This sketch was written by SparkFun Electronics, with lots of help from the Arduino community. Visit http://learn.sparkfun.com/products/2 for SIK information. Visit http://www.arduino.cc to learn about the Arduino. Version 2.0 6/2012 MDG */ // First we'll define the pins by name to make the sketch // easier to follow. // Here's a new trick: putting the word "const" in front of a // variable indicates that this is a "constant" value that will // never change. (You don't have to do this, but if you do, the // Arduino will give you a friendly warning if you accidentally // try to change the value, so it's considered good form.) const int RED_PIN = 9; const int GREEN_PIN = 10; const int BLUE_PIN = 11; // This variable controls how fast we loop through the colors. // (Try changing this to make the fading faster or slower.) int DISPLAY_TIME = 100; // In milliseconds void setup() { // Here we'll configure the Arduino pins we're using to // drive the LED to be outputs: pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT); } void loop() { showRGB(0, 0, 0); delay(250); showRGB(64, 64, 64); delay(250); showRGB(255, 255, 255); delay(250); showRGB(127, 0, 127); delay(250); } void showRGB(int r, int g, int b) { analogWrite(RED_PIN, r); analogWrite(GREEN_PIN, g); analogWrite(BLUE_PIN, b); }