/* Red Green Blue Blaster */
int redpin = 11; // select the pin for the red LED
int bluepin = 10; // select the pin for the blue LED
int greenpin = 9; // select the pin for the green LED
int val; // variable to store brightness level
void setup() {
pinMode(redpin, OUTPUT); // set red LED pin as output
pinMode(bluepin, OUTPUT); // set blue LED pin as output
pinMode(greenpin, OUTPUT);// set green LED pin as output
Serial.begin(9600); // initialize serial communication at 9600 baud rate
}
/*The value 255 is chosen because Arduino's analogWrite() uses 8-bit PWM, which ranges from 0 to 255.
It allows for 256 levels of brightness control, with 255 representing full brightness.*/
void loop() {
// Fade from fully bright to off
for(val = 255; val > 0; val--) // decrease brightness value from 255 to 0
{
analogWrite(11, val); // set the brightness of red LED
analogWrite(10, 255 - val); // set the brightness of blue LED (inversely proportional)
analogWrite(9, 128 - val); // set the brightness of green LED (range from 128 to 0)
Serial.println(val, DEC); // print the current brightness value in decimal format to Serial Monitor
delay(50); // short delay for smooth fading effect
}
// Fade from off to fully bright
for(val = 0; val < 255; val++) // increase brightness value from 0 to 255
{
analogWrite(11, val); // set the brightness of red LED
analogWrite(10, 255 - val); // set the brightness of blue LED (inversely proportional)
analogWrite(9, 128 - val); // set the brightness of green LED (range from 0 to 128)
Serial.println(val, DEC); // print the current brightness value in decimal format to Serial Monitor
delay(50); // short delay for smooth fading effect
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
rgb1:R
rgb1:COM
rgb1:G
rgb1:B