I know this is very basic, but I'm just started at getting back into Arduino. The main reason I'm posting this is so that the people who watch my video can see the code. Let me know what you think of this.
About the project: I am making some custom firniture for my room. I want to add some lighting to it. It is gonna be controlled by some pots, switches, ect. However, when you try to make white light with an RGB led, it is very impure. So what I'm gonna do is add pure white LEDs next to the RGB. This is how I plan to have it switch between the RGB, and the White LED.
int red = 11; // Red lead of RGB attached to pin 11
int green = 10; // Green lead of RGB attached to pin 10
int blue = 9; // Blue lead of RGB attached to pin 9
int white = 8; // White LED attached to pin 8
int redPot = 0; // Pot for controlling red value attached to analog pin 0
int greenPot = 1; // Pot for controlling green value attached to analog pin 1
int bluePot = 2; // Pot for controlling blue value attached to analog pin 2
int redVal; // Variable for storing the red value
int greenVal; // Variable for storing the green value
int blueVal; // Variable for storing the blue value
void setup() {
pinMode(red, OUTPUT); // Red pin is an output
pinMode(green, OUTPUT); // Green pin is an output
pinMode(blue, OUTPUT); // Blue pin is an output
pinMode(white, OUTPUT); // White pin is an output
}
void loop() {
redVal = analogRead(redPot); // Reads the value of the Red Pot, and stores the value in Red Val
greenVal = analogRead(greenPot); // Reads the value of the Green Pot, and stores the value in Green Val
blueVal = analogRead(bluePot); // Reads the value of the Blue Pot, and stores the value in Blue Val
redVal = map(redVal, 0, 1023, 0, 255); // Maps Red Val to fit the perameters of PWM
greenVal = map(greenVal, 0, 1023, 0, 255); // Maps Green Val to fit the perameters of PWM
blueVal = map(blueVal, 0, 1023, 0, 255); // Maps Blue Val to fit the perameters of PWM
if(redVal >= 250 && greenVal >= 250 && blueVal >= 250){ // If Red Val, Green Val, and Blue Val are all equal to or above 250
digitalWrite(red, LOW); // Turn the Red Pin off
digitalWrite(green, LOW); // Turn the Green Pin off
digitalWrite(blue, LOW); // Turn the Blue Pin off
digitalWrite(white, HIGH); // Turn the White Pin on
}
else{
analogWrite(red, redVal); // PWM the Red Pin to the value of Red Val
analogWrite(green, greenVal); // PWM the Green Pin to the value of Green Val
analogWrite(blue, blueVal); // PWM the Blue Pin to the value of Blue Val
digitalWrite(white, LOW); // Turn the White Pin off
}
}