How RGB LED Works :
RGB is Red Green and Blue LED's Together. There are 256 values for intensity (Brightness) for each color. with the help of Arduino PWM signals we can change those values and we can get verity of colors.
Here is simple Demonstration :
In this code We can put values from 0 to 255 for each R, G and B and get result color with the help of Serial monitor.
Circuit Diagram :
Code :
int RLED = 9;
int GLED = 10;
int BLED = 11;
int Rsat ;
int Gsat;
int Bsat;
void setup() {
Serial.begin(9600);
pinMode(RLED, OUTPUT);
pinMode(GLED, OUTPUT);
pinMode(BLED, OUTPUT);
}
void loop() {
Serial.println("Saturation For Red LED ? ");
while (Serial.available() == 0) {}
Rsat = Serial.parseInt();
Serial.println("Saturation For Green LED ? ");
while (Serial.available() == 0) {}
Gsat = Serial.parseInt();
Serial.println("Saturation For Blue LED ? ");
while (Serial.available() == 0) {}
Bsat = Serial.parseInt();
if (Rsat >= 255) {
Rsat = 255;
}
if (Gsat >= 255) {
Gsat = 255;
}
if (Bsat >= 255) {
Bsat = 255;
}
analogWrite(RLED, Rsat);
analogWrite(GLED, Gsat);
analogWrite(BLED, Bsat);
Serial.print("(");
Serial.print(Rsat);
Serial.print(", ");
Serial.print(Gsat);
Serial.print(", ");
Serial.print(Bsat);
Serial.println(")");
Serial.println(" ");
}
Post a Comment