This is the program code, for reference:
/*
RGB_LED_Color_Fade_Cycle.pde
Cycles through the colors of a RGB LED
Written for SparkFun Arduino Inventor's Kit CIRC-RGB
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// LED leads connected to PWM pins
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int BLUE_LED_PIN = 11;
int potval = 0;
int ledval = 0;
int potpin = 0;
int serval = 0;
// Used to store the current intensity level of the individual LEDs
int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;
void setup()
{
//myservo.attach(3); // attaches the servo on pin 3 to the servo object **RGB LED BREAKS IF UNCOMMENTED**
}
void loop() {
delay(50);
potval = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
ledval = map(potval, 0, 600, 1, 900);
if (ledval < 310) {
redIntensity = map(ledval, 1, 300, 1, 255);
greenIntensity = 0;
blueIntensity = map(ledval, 1, 300, 255, 1);
}
else if (ledval < 610 && ledval > 300) {
redIntensity = map(ledval, 310, 610, 255, 1);
greenIntensity = map(ledval, 310, 610, 1, 255);
blueIntensity = 0;
}
else if (ledval > 600 && ledval < 900) {
redIntensity = 0;
greenIntensity = map(ledval, 610, 910, 255, 1);
blueIntensity = map(ledval, 610, 910, 1, 255);
}
else {
redIntensity = 0;
blueIntensity = 0;
greenIntensity = 0;
}
analogWrite(RED_LED_PIN, redIntensity);
analogWrite(BLUE_LED_PIN, blueIntensity);
analogWrite(GREEN_LED_PIN, greenIntensity);
}