//******************************************************
// * *
// * NAME : Rasesh Patel *
// * Program Name : PWM LED Fader.ino *
// * Date : 2023-03-21 *
// * Desc : This program has an rgb LED which *
// * is controlled by potentiometer *
// * and the rgb values are displayed *
// * on a LCD display *
// * *
//******************************************************
#include <LiquidCrystal_I2C.h> // including lcd display libraries
#define I2C_ADDR 0x27 // defining address of the lcd
#define LCD_COLUMNS 16 // defining number of coloumns for lcd
#define LCD_LINES 2 // defining number of line for lcd
LiquidCrystal_I2C lcd (I2C_ADDR, LCD_COLUMNS, LCD_LINES); //creating a lcd project based on the columns and lines defined
int redLED = 6; // pin for redLED
int greenLED = 5; // pin for greenLED
int blueLED = 3; // pin for blueLEd
int redPot = A0; // pin for redLED potentiometer
int greenPot = A1; // pin for greenLED potentiometer
int bluePot = A2; // pin for blueLED potentiometer
int redValue = 0; // value from the potentiometer
int greenValue = 0; // value from the potentiometer
int blueValue = 0; // value from the potentiometer
void setup() {
lcd.init(); // starting the lcd display
lcd.backlight(); // turn on the lcd display backlight
lcd.setCursor(0, 0); // set cursor on lcd display
lcd.print("RPLED Fader v1.0"); // intial print on the lcd dispay
// put your setup code here, to run once:
pinMode(redLED, OUTPUT); // setting redLED pin as an output
pinMode(greenLED, OUTPUT); // setting greenLED pin as an output
pinMode(blueLED, OUTPUT); // setting blueLED pin as an output
analogWrite(redLED, 255); // turning the redLED off to start
analogWrite(greenLED, 255); // turning the greenLED off to start
analogWrite(blueLED, 255); // turning the blueLED off to start
delay(2000); // wait 2000 ms
lcd.setCursor(0,0); // set cursor location on lcd display
lcd.print("RED GRN BLUE"); // print the headers for the rgb values on the lcd display
} // end setup()
void loop() {
// put your main code here, to run repeatedly:
redValue = analogRead(redPot)/4; // taking the potentiometer input value and dividing by 4 so it ranges from 0-255
greenValue = analogRead(greenPot)/4; // taking the potentiometer input value and dividing by 4 so it ranges from 0-255
blueValue = analogRead(bluePot)/4; // taking the potentiometer input value and dividing by 4 so it ranges from 0-255
analogWrite(redLED, redValue); // assigning red rgb value to redLED
analogWrite(greenLED, greenValue); // assigning green rgb value to greenLED
analogWrite(blueLED, blueValue); // assigning blue rgb value to blueLED
lcd.setCursor(0,1); // set cursor location on lcd display
lcd.print(redValue); // display the rgb value of redLED potentiometer
lcd.setCursor(6,1); // set cursor location on lcd display
lcd.print(greenValue); // display the rgb value of greenLED potentiometer
lcd.setCursor(12,1); // set cursor location on lcd display
lcd.print(blueValue); // display the rgb value of blueLED potentiometer
}// end loop()