Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
felixthecat8a committed Jan 1, 2025
1 parent 1ccdc11 commit c637a6f
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 16 deletions.
37 changes: 30 additions & 7 deletions examples/ColorWheelSpin/ColorWheelSpin.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
/**
* ColorWheelSpin.ino
* For an RGB LCD with 18 pins, set pin 15 to HIGH.
* Pin 16 is red, pin 17 is green and pin 18 is blue.
* On the Arduino board, choose 3 PWM pins (denoted by ~)
* This sketch will change the color of the backlight as the LCD displays
*/
*
* This example demonstrates how to smoothly transition the RGB backlight
* of an LCD through a color wheel using the LCD_BacklightRGB library.
*
* Connections:
* - Use an RGB LCD with 18 pins:
* - Pin 15: Connect to HIGH for backlight power.
* - Pin 16: Red channel (connect to PWM pin ~6).
* - Pin 17: Green channel (connect to PWM pin ~9).
* - Pin 18: Blue channel (connect to PWM pin ~10).
* - LCD Data Pins:
* - RS: Pin 12
* - Enable: Pin 11
* - D4: Pin 5
* - D5: Pin 4
* - D6: Pin 3
* - D7: Pin 2
* - R/W: GND
* - VSS: GND
* - VCC: 5V
* - Contrast Adjustment:
* - Connect a 10kΩ potentiometer to the contrast (V0) pin.
* - Middle pin of the potentiometer: Connect to the V0 pin (pin 3) of the LCD.
* - One outer pin: Connect to GND.
* - Other outer pin: Connect to 5V.
*
*/

#include <LiquidCrystal.h>
#include <LCD_BacklightRGB.h>
Expand All @@ -16,7 +38,7 @@ const int redPin = 6, greenPin = 9, bluePin = 10;
LCD_BacklightRGB backlight(redPin, greenPin, bluePin);

unsigned long previousMillis = 0;
const long interval = 1000;
const long interval = 100;
int index = 0;

void setup() {
Expand All @@ -25,7 +47,6 @@ void setup() {
// Initiate the RGB pins.
backlight.begin();
// Optional: Set the brightness level (0 - 255).
// Defaults to 255 if not set.
backlight.setBrightness(150);
lcd.print("hello, world!");
}
Expand All @@ -34,10 +55,12 @@ void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Smoothly transitions between colors based on the index value.
backlight.scaleColor(index, 0, 255);
index++;
if (index >= 255) {
index = 0;
}
// Update code here.
}
}
28 changes: 24 additions & 4 deletions examples/HelloWorld/HelloWorld.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
/**
* HelloWorld.ino
* For an RGB LCD with 18 pins, set pin 15 to HIGH.
* Pin 16 is red, pin 17 is green and pin 18 is blue.
* On the Arduino board, choose 3 PWM pins (denoted by ~)
*/
*
* Connections:
* - Use an RGB LCD with 18 pins:
* - Pin 15: Connect to HIGH for backlight power.
* - Pin 16: Red channel (connect to PWM pin ~6).
* - Pin 17: Green channel (connect to PWM pin ~9).
* - Pin 18: Blue channel (connect to PWM pin ~10).
* - LCD Data Pins:
* - RS: Pin 12
* - Enable: Pin 11
* - D4: Pin 5
* - D5: Pin 4
* - D6: Pin 3
* - D7: Pin 2
* - R/W: GND
* - VSS: GND
* - VCC: 5V
* - Contrast Adjustment:
* - Connect a 10kΩ potentiometer to the contrast (V0) pin.
* - Middle pin of the potentiometer: Connect to the V0 pin (pin 3) of the LCD.
* - One outer pin: Connect to GND.
* - Other outer pin: Connect to 5V.
*
*/

#include <LiquidCrystal.h>
#include <LCD_BacklightRGB.h>
Expand Down
128 changes: 128 additions & 0 deletions examples/RGB_LED/RGB_LED.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/**
* RGB_LED.ino
*
* This sketch will change the color of an RGB LED using the sub libraries available.
*/

#include <Arduino.h>
#include <LCD_BacklightRGB.h>

// Set the RGB pins for the RGB LED. Use PWM pins denoted by a ~ symbol.
const int redPin = 11, greenPin = 10, bluePin = 9;
BacklightRGB led(redPin, greenPin, bluePin);

BacklightCW cw;

void showColor(const int color[3]);
void spinColorWheel();

void setup() {
led.begin();
led.setBrightness(50);
}

void loop() {
showColor(BacklightColors::WHITE);
showColor(BacklightColors::HOTPINK);
showColor(BacklightColors::RED);
showColor(BacklightColors::ORANGE);
showColor(BacklightColors::YELLOW);
showColor(BacklightColors::LIME);
showColor(BacklightColors::GREEN);
showColor(BacklightColors::TEAL);
showColor(BacklightColors::CYAN);
showColor(BacklightColors::SKY);
showColor(BacklightColors::BLUE);
showColor(BacklightColors::PURPLE);
showColor(BacklightColors::MAGENTA);
showColor(BacklightColors::BLACK);
spinColorWheel();
}

void showColor(const int color[3]) {
led.setRGB(color); delay(500);
}

void spinColorWheel() {
for (int i = 0; i < 255; i++) {
led.setRGB(cw.mapToColorWheel(i, 0, 255)); delay(15);
}
}


/**
* RGB_LED.ino
*
* This example demonstrates how to control an RGB LED using the LCD_BacklightRGB library.
* It cycles through predefined colors and then smoothly transitions through the color wheel.
*
* Features:
* - Predefined colors using BacklightColors.
* - Smooth color transitions using the color wheel (BacklightCW).
* - Adjustable brightness for the RGB LED.
*
* Connections:
* - Red Pin: PWM pin ~11
* - Green Pin: PWM pin ~10
* - Blue Pin: PWM pin ~9
*/

#include <Arduino.h>
#include <LCD_BacklightRGB.h>

// Set the RGB pins for the RGB LED. Use PWM pins denoted by a ~ symbol.
const int redPin = 11, greenPin = 10, bluePin = 9;
BacklightRGB led(redPin, greenPin, bluePin);

// Color wheel utility
BacklightCW cw;

// Display a predefined color
void showColor(const int color[3]);

// Spin the color wheel
void spinColorWheel();

void setup() {
// Initialize the RGB LED
led.begin();

// Set brightness (0-255)
led.setBrightness(50);
}

void loop() {
// Cycle through predefined colors
showColor(BacklightColors::WHITE);
showColor(BacklightColors::HOTPINK);
showColor(BacklightColors::RED);
showColor(BacklightColors::ORANGE);
showColor(BacklightColors::YELLOW);
showColor(BacklightColors::LIME);
showColor(BacklightColors::GREEN);
showColor(BacklightColors::TEAL);
showColor(BacklightColors::CYAN);
showColor(BacklightColors::SKY);
showColor(BacklightColors::BLUE);
showColor(BacklightColors::PURPLE);
showColor(BacklightColors::MAGENTA);
showColor(BacklightColors::BLACK);

// Smoothly transition through the color wheel
spinColorWheel();
}

void showColor(const int color[3]) {
// Set the LED to the specified RGB color
led.setRGB(color);
delay(500);
}

void spinColorWheel() {
// Smoothly transition through the color wheel
for (int i = 0; i < 255; i++) {
led.setRGB(cw.mapToColorWheel(i, 0, 255));
delay(15);
}
}

35 changes: 30 additions & 5 deletions examples/SimpleExample/SimpleExample.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
/**
* SimpleExample.ino
* For an RGB LCD with 18 pins, set pin 15 to HIGH.
* Pin 16 is red, pin 17 is green and pin 18 is blue.
* On the Arduino board, choose 3 PWM pins (denoted by ~)
*
* This sketch will loop through the different colors and display the color name.
* This example loops through all of the default colors available in the library.
*/
* This example loops through several default colors available in the library.
*
* Connections:
* - Use an RGB LCD with 18 pins:
* - Pin 15: Connect to HIGH for backlight power.
* - Pin 16: Red channel (connect to PWM pin ~6).
* - Pin 17: Green channel (connect to PWM pin ~9).
* - Pin 18: Blue channel (connect to PWM pin ~10).
* - LCD Data Pins:
* - RS: Pin 12
* - Enable: Pin 11
* - D4: Pin 5
* - D5: Pin 4
* - D6: Pin 3
* - D7: Pin 2
* - R/W: GND
* - VSS: GND
* - VCC: 5V
* - Contrast Adjustment:
* - Connect a 10kΩ potentiometer to the contrast (V0) pin.
* - Middle pin of the potentiometer: Connect to the V0 pin (pin 3) of the LCD.
* - One outer pin: Connect to GND.
* - Other outer pin: Connect to 5V.
*
*/

#include <LiquidCrystal.h>
#include <LCD_BacklightRGB.h>
Expand Down Expand Up @@ -65,4 +86,8 @@ void loop() {
backlight.setMagenta();
lcd.setCursor(0,1); lcd.print("Magenta"); lcd.print(" ");
delay(1000);

backlight.setPink();
lcd.setCursor(0,1); lcd.print("Pink"); lcd.print(" ");
delay(1000);
}

0 comments on commit c637a6f

Please sign in to comment.