/*
MSJ Researchers World
Date - 18th NOV 2024
Mentor - Mr. Siranjeevi M
Contact - 7373771991
*/
// Define pins for the RGB LED
const int redPin = 3; // PWM pin for red
const int greenPin = 5; // PWM pin for green
const int bluePin = 6; // PWM pin for blue
// Define pins for the potentiometers
const int redPot = A0; // Potentiometer for red
const int greenPot = A1; // Potentiometer for green
const int bluePot = A2; // Potentiometer for blue
void setup() {
// Set RGB LED pins as output
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
// Initialize serial communication (optional for debugging)
Serial.begin(9600);
}
void loop() {
// Read potentiometer values (0-1023)
int redValue = analogRead(redPot);
int greenValue = analogRead(greenPot);
int blueValue = analogRead(bluePot);
// Map potentiometer values to PWM range (0-255)
redValue = map(redValue, 0, 1023, 0, 255);
greenValue = map(greenValue, 0, 1023, 0, 255);
blueValue = map(blueValue, 0, 1023, 0, 255);
// Write the values to the RGB LED
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
// Print the values to the Serial Monitor (optional for debugging)
Serial.print("Red: ");
Serial.print(redValue);
Serial.print(" | Green: ");
Serial.print(greenValue);
Serial.print(" | Blue: ");
Serial.println(blueValue);
// Small delay for stability
delay(50);
}