This page is just a bunch of random code that was not directly used in the camp.
Getting the colors to fade
See if you can get your RGB LED to fade in and out with this code. Let's see if we can understand it too.
#define BLUE 3 //We are defining the different colors
#define GREEN 5 //to the different pins
#define RED 6 // change the numbers to what you have plugged in
void setup(){
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
int redValue; // define variables
int greenValue;
int blueValue;
void loop(){
#define delayTime 10 // fading time between colors
redValue = 255; // this code starts with red on, choose a value between 1 and 255 to change the color.
greenValue = 0;
blueValue = 0;
for(int i = 0; i < 255; i += 1) { // fades out red bring green full when i=255
redValue -= 1; // makes red dimmer by one each delay time
greenValue += 1; // makes green brighter by one each delay time
analogWrite(RED, redValue);
analogWrite(GREEN, greenValue);
delay(delayTime);
}
for(int i = 0; i < 255; i += 1) { // fades out green bring blue full when i=255
greenValue -= 1;
blueValue += 1;
analogWrite(GREEN, greenValue);
analogWrite(BLUE, blueValue);
delay(delayTime);
}
for(int i = 0; i < 255; i += 1) {// fades out blue bring red full when i=255
blueValue -= 1;
redValue += 1;
analogWrite(BLUE, blueValue);
analogWrite(RED, redValue);
delay(delayTime);
}
}
#define BLUE 3 //We are defining the different colors
#define GREEN 5 //to the different pins
#define RED 6 // change the numbers to what you have plugged in
void setup(){
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
int redValue; // define variables
int greenValue;
int blueValue;
void loop(){
#define delayTime 10 // fading time between colors
redValue = 255; // this code starts with red on, choose a value between 1 and 255 to change the color.
greenValue = 0;
blueValue = 0;
for(int i = 0; i < 255; i += 1) { // fades out red bring green full when i=255
redValue -= 1; // makes red dimmer by one each delay time
greenValue += 1; // makes green brighter by one each delay time
analogWrite(RED, redValue);
analogWrite(GREEN, greenValue);
delay(delayTime);
}
for(int i = 0; i < 255; i += 1) { // fades out green bring blue full when i=255
greenValue -= 1;
blueValue += 1;
analogWrite(GREEN, greenValue);
analogWrite(BLUE, blueValue);
delay(delayTime);
}
for(int i = 0; i < 255; i += 1) {// fades out blue bring red full when i=255
blueValue -= 1;
redValue += 1;
analogWrite(BLUE, blueValue);
analogWrite(RED, redValue);
delay(delayTime);
}
}