Skip to content

Commit

Permalink
added setColor method to setRGB
Browse files Browse the repository at this point in the history
  • Loading branch information
felixthecat8a committed Jun 20, 2024
1 parent 8ca7f55 commit 01eb100
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This library allows interfacing with an 18-pin RGB LCD display backlight connected directly to an Arduino board. It enables the user to control the RGB backlight using Arduino. This library is meant to be used alongside the LiquidCrystal library.

On the RGB LCD, set pin 15 to HIGH. Pin 16 is red, pin 17 is green and pin 18 is blue. This sketch will loop through the different colors and display the color name. The code is based on a function that can be used to control the colors on an RGB LED.
On the RGB LCD display module, set pin 15 to HIGH. Pin 16 is red, pin 17 is green and pin 18 is blue. This sketch will loop through the different colors and display the color name. The code is based on a function that can be used to control the colors on an RGB LED.

## Installation

Expand Down Expand Up @@ -40,4 +40,4 @@ void loop() {
```
## RGB LCD Displays
Some of the displays out there are the Adafruit RGB LCD displays available in [backlight positive](https://www.adafruit.com/product/398) and [backlight negative](https://www.adafruit.com/product/399). Another RGB LCD out there is [this one](https://www.amazon.com/Character-Negative-Backlight-Arduino-projects/dp/B00CRSF37I) from Winstar.
Some of the RGB displays out there are the Adafruit RGB LCD displays available in [backlight positive](https://www.adafruit.com/product/398) and [backlight negative](https://www.adafruit.com/product/399). Another RGB LCD available out there is [this one](https://www.amazon.com/Character-Negative-Backlight-Arduino-projects/dp/B00CRSF37I) from Winstar on Amazon.
2 changes: 0 additions & 2 deletions src/Colors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ const int Colors::RED[3] = {255, 10, 10};
const int Colors::ORANGE[3] = {255, 100, 10};
const int Colors::YELLOW[3] = {255, 255, 10};
const int Colors::GREEN[3] = {10, 255, 10};
const int Colors::TEAL[3] = {10, 128, 128};
const int Colors::CYAN[3] = {10, 255, 255};
const int Colors::BLUE[3] = {10, 10, 255};
const int Colors::VIOLET[3] = {128, 10, 128};
const int Colors::MAGENTA[3] = {255, 10, 255};
const int Colors::WHITE[3] = {255, 255, 255};
const int Colors::BLACK[3] = {0, 0, 0};
2 changes: 0 additions & 2 deletions src/Colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class Colors {
static const int ORANGE[3];
static const int YELLOW[3];
static const int GREEN[3];
static const int TEAL[3];
static const int CYAN[3];
static const int BLUE[3];
static const int VIOLET[3];
static const int MAGENTA[3];
static const int WHITE[3];
static const int BLACK[3];
Expand Down
20 changes: 9 additions & 11 deletions src/LCD_BacklightRGB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ void LCD_BacklightRGB::begin() {
pinMode(_bluePin, OUTPUT);
}

void LCD_BacklightRGB::setRGB(int red, int green, int blue) {
red = constrain(red, minRGB, maxRGB);
green = constrain(green, minRGB, maxRGB);
blue = constrain(blue, minRGB, maxRGB);

int LCD_BacklightRGB::setColor(int color) {
color = constrain(color, minRGB, maxRGB);
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
color = 255 - color;
#endif
return color;
}

analogWrite(_redPin, red);
analogWrite(_greenPin, green);
analogWrite(_bluePin, blue);
void LCD_BacklightRGB::setRGB(int red, int green, int blue) {
analogWrite(_redPin, setColor(red));
analogWrite(_greenPin, setColor(green));
analogWrite(_bluePin, setColor(blue));
}

void LCD_BacklightRGB::setDefaultColor(const int color[3]) {
Expand Down
1 change: 1 addition & 0 deletions src/LCD_BacklightRGB.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class LCD_BacklightRGB {
private:
int _redPin, _greenPin, _bluePin;
const int minRGB = 0, maxRGB = 255;
int setColor(int color);
void setDefaultColor(const int color[3]);

public:
Expand Down

0 comments on commit 01eb100

Please sign in to comment.