#include <LiquidCrystal_I2C.h>
/*
******************************************
******************************************
** Name: Liam dutot **
** Prog Name: PWM LED FADER **
** Date: 09/26/2024 **
** Desc: control LED color **
** **
******************************************
******************************************
*/
#define I2C_ADDR 0x27
#define LCD_COLLUMS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd (I2C_ADDR, LCD_COLLUMS, LCD_LINES);
int redLed = 6;
int greenLed = 5;
int blueLed = 3;
int redPot = A0;
int greenPot = A2;
int bluePot = A1;
int red = 0;
int green = 0;
int blue = 0;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor (0, 0);
lcd.print("*LED FADER v1.0*");
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode (blueLed, OUTPUT);
analogWrite(redLed, 255);
analogWrite(greenLed, 255);
analogWrite(blueLed, 255);
delay(200);
lcd.setCursor (0, 0);
lcd.print ("RED GREEN BLUE");
} // 3end setup()
void loop() {
red = (analogRead (redPot) / 4);
green = (analogRead (greenPot) / 4);
blue = (analogRead (bluePot) / 4);
analogWrite (redLed, red);
analogWrite (greenLed, green);
analogWrite (blueLed, blue);
lcd.setCursor (0, 1);
lcd.print (padThree(red));
lcd.setCursor (6, 1);
lcd.print (padThree(green));
lcd.setCursor (12, 1);
lcd.print (padThree(blue));
} // end loop()
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTIONS BELOW @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// NAME : padThree()
// INPUTS : 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()
// here stringVal is correct length
return stringVal;
}// end padThree()
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@