/*
***************************************************************
** Name: Christian Veselinovic **
** Project name: Arduino PWM LED Fader **
** Date: Sep 26 **
** Description: Light up an RGB led and **
** use potentiometert to **
** control color **
***************************************************************
*/
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // set ip adress
#define LCD_COLUMNS 16 // assign # of columns for IDC display
#define LCD_LINES 2 // assign # of lines for ICD display
LiquidCrystal_I2C lcd (I2C_ADDR, LCD_COLUMNS, LCD_LINES); // assigns values for IDC
int redLed = 6; // set pin value for red led
int greenLed = 5; // set pin value for green led
int blueLed = 3; // set pin value for blue led
int redPot = A0; // keep value for red Pot
int greenPot = A1; // keep value for green Pot
int bluePot = A2; // keep value for blue Pot
int red = 0; // keep value for red led
int green = 0; // keep value for green led
int blue = 0; // keep value for blue led
void setup() {
lcd.init(); // sets interface to ICD screen
lcd.backlight(); // Turn onbackl light
lcd.setCursor(0, 0);
lcd.print("-LED FADER v1.0- "); // Print title LED FADER on screen
pinMode(redLed, OUTPUT); // Make red led an output
pinMode(greenLed, OUTPUT); // Make green led an output
pinMode(blueLed, OUTPUT); // Make blue led an output
analogWrite(redLed, 255); // controls the amount of red color to change the leds color
analogWrite(greenLed, 255); // controls the amount of greem color to change the leds color
analogWrite(blueLed, 255); // controls the amount of blue color to change the leds color
delay(2000); // wait
lcd.setCursor(0, 0);
lcd.print("RED GRN BLU "); // Print led colors
}
void loop() {
red = (analogRead(redPot) / 4); // creates an rgb value for red
green = (analogRead(greenPot) / 4); // creates an rgb value for green
blue = (analogRead(bluePot) / 4); // creates an rgb value for blue
analogWrite(redLed, red ); // controls amount of red color
analogWrite(greenLed, green ); // controls amount of green color
analogWrite(blueLed, blue); // controls amount of blue color
lcd.setCursor(0, 1); // sets cursor column to 0 row 1
lcd.print(red); // print red value
lcd.setCursor(6, 1); // sets cursor column to 6 row 1
lcd.print(green); // print red value
lcd.setCursor(12, 1); // sets cursor column to 12 row 1
lcd.print(blue); // print red value
}