#include <LiquidCrystal_I2C.h>
/*
************************
************************
** **
** Name: Alex Szabo **
** **
** Prog:PWM LED FADER**
** **
** Date: oct 1 **
** **
** Desc: light fader **
** with screen **
** **
** **
************************
************************
*/
#define I2C_ADDR 0x27 // set up the ip adress
#define LCD_COLUMNS 16 // assigns number of columns for ldc display
#define LCD_LINES 2 // asssigns number of lines for lcd display
LiquidCrystal_I2C lcd (I2C_ADDR, LCD_COLUMNS, LCD_LINES); // assigns set values for lcd display
int redLed = 6; // sets pin val for red led
int greenLed = 5; //sets pin val for green led
int blueLed = 3; // sets pin val for the blue led
int redPot = A1; // hold the value for the red pot
int greenPot = A2; // hold the value for the green pot
int bluePot = A3; // hold the value for the blue po
int red = 0; // holds value for red led
int green = 0; // holds value for green led
int blue = 0; // holds value for blue led
void setup() {
lcd.init(); // set interface to lcd screen
lcd.backlight(); // turn on back light
lcd.setCursor(0, 0); // set cursor to (0,0)
lcd.print("-LED FADER v1.0-"); // print led fader v1
pinMode(redLed, OUTPUT); // red led output
pinMode(greenLed, OUTPUT); // green led output
pinMode(blueLed, OUTPUT); // blu3e led output
analogWrite(redLed, 255); // 0 (ON) - 255 ( OFF)
analogWrite(greenLed, 255); // 0 (ON) - 255 ( OFF)
analogWrite(blueLed, 255); // 0 (ON) - 255 ( OFF)
delay(2500); // delay by 2500 seconds
lcd.setCursor(0, 0); // set cursor to (0,0)
lcd.print("RED GRN BLU "); // prints red grn blu
}
void loop() {
blue = (analogRead(bluePot ) /4); // created rgb value blue
red = (analogRead(redPot ) /4); // created rgb value red
green = (analogRead(greenPot ) /4); // created rgb value green
analogWrite(blueLed , blue); // prints out blue value to blue led
analogWrite(redLed , red); // prints out red value to red led
analogWrite(greenLed , green); // prints out green value to green led
lcd.setCursor(0, 1); // moves lcd cursor to (0, 1)
lcd.print (padThree(red)); // prints out red value
lcd.setCursor(6, 1); // moves lcd cursor to (6, 1)
lcd.print (padThree(green)); // prints out green value
lcd.setCursor(12, 1); // moves lcd cursor to (12, 1)
lcd.print (padThree(blue)); // prints out blue value
} // end loop
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// FUNCTION HEADER
// NAME: padThree()
// INPTS : an integer
// Returns: A string
// Desc: Reads in int val, turns it to a String and pads it to 3 long
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
String padThree( int val ) {
String stringVal = String (val);
if (stringVal.length() == 1) {
stringVal = " " + stringVal;
} else if (stringVal.length() == 2) {
stringVal =" " + stringVal;
} // end if()
return stringVal;
} // end padThree