/*
Zainab Khan
LEDFader.ino
March 28, 2025
This program has 3 potentiometers
that control the RGB values of a
RGB LED while desplaying that value
on a lcd screen
*/
#include <LiquidCrystal_I2C.h> // include the library for the LCD screen
LiquidCrystal_I2C lcd (0x27, 16, 2); // I2C address is 0x27, 16 columns, 2 rows
int ledRed = 11; // red for RGB LED is connected to pin 11
int ledGreen = 10; // green for RGB LED is connected to pin 10
int ledBlue = 9; // blue for RGB LED is connected to pin 9
int potRed = A0; // potentiometer for red is connected to A0
int potGreen = A1; // potentiometer for green is connected to A1
int potBlue = A2; // potentiometer for blue is connected to A2
int potValRed; // variable to store potentiometer reading for red (0-1023)
int potValGreen; // variable to store potentiometer reading for green (0-1023)
int potValBlue; // variable to store potentiometer reading for blue (0-1023)
int red; // variable to hold potentiometer value for red (0-255)
int green; // variable to hold potentiometer value for green (0-255)
int blue; // variable to hold potentiometer value for blue (0-255)
void setup() {
lcd.init(); //initialize the lcd screen
lcd.backlight(); // turn on the backlight
lcd.setCursor(0,0); // move cursor to first column on top row
lcd.print("*LED FADER v1.0*"); // print on lcd "*LED FADER v1.0*"
delay(2000); // delay of 2 seconds
lcd.setCursor(0,0); // move cursor to first column on top row (overwrites previous print)
lcd.print("RED GREEN BLUE "); // print on lcd "RED GREEN BLUE"
} // end of void setup
void loop() {
potValRed = analogRead(potRed); // read the value from the potentiometer for red
potValGreen = analogRead(potGreen); // read the value from the potentiometer for green
potValBlue = analogRead(potBlue); // read the value from the potentiometer for blue
red = map(potValRed, 0, 1023, 0, 255); // changes the 0-1023 reading to a 0-255 scale
green = map(potValGreen, 0, 1023, 0, 255); // changes the 0-1023 reading to a 0-255 scale
blue = map(potValBlue, 0, 1023, 0, 255); // changes the 0-1023 reading to a 0-255 scale
analogWrite(ledRed, red); // output value of red (0-255) to RGB LED for red
analogWrite(ledGreen, green); // output value of green (0-255) to RGB LED for green
analogWrite(ledBlue, blue); // output value of red blue (0-255) to RGB LED for blue
lcd.setCursor (0,1); // move cursor to first column on bottom row
lcd.print(red); // print the value of red on lcd
lcd.print(" ");
lcd.setCursor (6,1); // move cursor to 6th column on bottom row
lcd.print(green); // print the value of green on lcd
lcd.print(" ");
lcd.setCursor (12,1); // moves cursor to 12th column on bottom row
lcd.print(blue); // print the value of blue on lcd
lcd.print(" ");
} // end of void loop