#include <LiquidCrystal_I2C.h>
//*************************************************************************************************
//* Name Rhys Miller *
//* Program PROGRAM #5- PWM LED Fader *
//* Date March 21 2024 *
//* Desc Adjustable RGB LED using potentiometers and displays RGB values on a I2C lcd display *
//*************************************************************************************************
// define LED display
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
// create led display with defined parameters
LiquidCrystal_I2C lcd(I2C_ADDR,LCD_COLUMNS, LCD_LINES);
// define LED pin numbers
int REDpin = 11;
int GREpin = 10;
int BLUpin = 9;
void setup() {
// put your setup code here, to run once:
// initialize LED Display
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("*LED FADER v1.0*");
delay(2000);
// print RGB Colour Names to Display
lcd.setCursor(0,0);
lcd.print("RED GREEN BLUE");
// set pin modes for LED Outputs
pinMode(REDpin,OUTPUT);
pinMode(BLUpin, OUTPUT);
pinMode(GREpin, OUTPUT);
// set pin modes for LED Inputs
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// create variables for RGB values
int RED = (analogRead(A0)-3)/4; // make potentiometer input max 255
int GRE = (analogRead(A1)-3)/4; // make potentiometer input max 255
int BLU = (analogRead(A2)-3)/4; // make potentiometer input max 255
analogWrite(REDpin,RED); // write RED value for RBG LED to REDpin
analogWrite(GREpin,GRE); // write GREEN value for RGB LED to GREpin
analogWrite(BLUpin,BLU); // write BLUE value for RGB LED to BLUpin
lcd.setCursor(0,1); // move cursor to second line
lcd.print(RED); // print red rgb value to lcd display
lcd.setCursor(5,1); // move cursour to next colour (Green)
lcd.print(GRE); // print green rgb value to lcd display
lcd.setCursor(12,1); // move cursor to next colour (Blue)
lcd.print(BLU); // print blue rgb value to lcd display
}