//***************************************************************************
//* *
//* NAME : Saleem Abounaag *
//* Program Name : program.ino *
//* Date : 2023-03-21 *
//* Desc : To use the Arduino Uno to control a RGB LED *
//* To analog read data from a potentiometer *
//* To connect and use an I2C bus LCD Display (16x2) *
//***************************************************************************
#include <LiquidCrystal_I2C.h> // include LCD display libraries
#define I2C_ADDR 0x27 // define address of the LCD
#define LCD_COLUMNS 16 // define number of culumns for LCD
#define LCD_LINES 2 // define number of lines for LCD
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES); // make LCD project from the lines/columns defined
int redLED = 6; // pin for red LED
int greenLED = 5; // pin for green LED
int blueLED = 3; // pin for blue LED
int redPOT = A0; // pin for red POT
int greenPOT = A1; // pin for green POT
int bluePOT = A2; // pin for blue POT
int blueValue = 0; // potentiometer value for blue
int redValue = 0; // potentiometer value for red
int greenValue = 0; // potentiometer value for green
void setup() {
lcd.init(); // start LCD display
lcd.backlight(); // turn on backlight for LCD display
lcd.setCursor(0,0); // set cursor on LCD display
lcd.print("kbag753"); // starting print on LCD display
pinMode(redLED, OUTPUT); // set red LED as an output
pinMode(greenLED, OUTPUT); // set green LED as an output
pinMode(blueLED, OUTPUT); // set blue LED as an output
analogWrite(redLED,255); // turn off red LED
analogWrite(greenLED,255); // turn off green LED
analogWrite(blueLED,255); // turn off blue LED
delay(2000); // delay of 2 seconds for the user to read display
lcd.setCursor(0,0); // set cursor on LCD display
lcd.print("RED GRN BLU"); // put headers for values on LCD display
}
void loop() {
redValue = analogRead(redPOT)/4; // read red potentiometer and divide the value by 4 for the red LED value
greenValue = analogRead(greenPOT)/4; // read green potentiometer and divide the value by 4 for the green LED value
blueValue = analogRead(bluePOT)/4; // read blue potentiometer and divide the value by 4 for the blue LED value
analogWrite(redLED, redValue); // make the red RGB value to red LED
analogWrite(greenLED, greenValue); // make the green RGB value to green LED
analogWrite(blueLED, blueValue); // make the blue RGB value to blue LED
lcd.setCursor(0,1); // set cursor on LCD display to (0,1)
lcd.print(redValue); // put red RGB value on LCD
lcd.setCursor(6,1); // set cursor on LCD display to (6,1)
lcd.print(greenValue); // put green RGB value on LCD
lcd.setCursor(12,1); // set cursor on LCD display to (12,1)
lcd.print(blueValue); // put blue RGB value on LCD
//end loop
}