#include <LiquidCrystal_I2C.h>
/*
Name: Indervir Rai
Program Name: Arduino PWN LED Fader
Date: 2025-03-31
Program full description: To use the Arduino Uno to control a RGB LED, and
analog read data from a potentiometer.
*/
#define I2C_ADDR 0x27 // defines I2C_ADDR
#define LCD_COLUMNS 16 // defines LCD_COLLUMS
#define LCD_LINES 2 // defines LCD_LINES
int redPotPin = A0;
int redPotentiometerValue;
int redValue;
int redPin = 11;
int greenPotPin = A1;
int greenPotentiometerValue;
int greenValue;
int greenPin = 10;
int bluePotPin = A2;
int bluePotentiometerValue;
int blueValue;
int bluePin = 9;
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("*LED FADER v1.0*");
delay(2000);
lcd.setCursor(0,0);
lcd.print("RED GREEN BLUE");
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
}
void loop() {
redPotentiometerValue = analogRead(redPotPin); // read the value from the potentiometer
redValue = map(redPotentiometerValue, 0, 1023, 0, 255); // this changes the reading to a 0-255
analogWrite(redPin, redValue);
lcd.setCursor (0,1); // move cursor to (0,1)
lcd.print(redValue);
lcd.print(" ");
greenPotentiometerValue = analogRead(greenPotPin); // read the value from the potentiometer
greenValue = map(greenPotentiometerValue, 0, 1023, 0, 255); // this changes the reading to a 0-255
analogWrite(greenPin, greenValue);
lcd.setCursor (6,1); // move cursor to (6,1)
lcd.print(greenValue);
lcd.print(" ");
bluePotentiometerValue = analogRead(bluePotPin); // read the value from the potentiometer
blueValue = map(bluePotentiometerValue, 0, 1023, 0, 255); // this changes the reading to a 0-255
analogWrite(bluePin, blueValue);
lcd.setCursor (12,1); // move cursor to (12,1)
lcd.print(blueValue);
lcd.print(" ");
}