An Arduino-compatible library to simplify control of RGB and RGBW LEDs with support for both discrete LED pins and NeoPixel (WS2812) addressable LEDs.
Disclaimer: This README file was AI-generated, but checked for accuracy by a human.
- Dual LED Support: Control both discrete RGB/RGBW LEDs (via PWM pins) and NeoPixel addressable LEDs
- Stimulus Queue System: Pre-program different color/duration combinations
- Automatic Timing: Built-in timer for automatic LED shutoff after specified durations
- Flexible Color Control: Set colors using individual RGB/RGBW values or packed 32-bit integers
- Polarity Control: Configure active-high or active-low LED control
- Predefined Colors: Built-in color constants for common colors (red, yellow, green, cyan, blue, magenta)
- Download this repository as a ZIP file
- In Arduino IDE, go to Sketch → Include Library → Add .ZIP Library
- Select the downloaded ZIP file
- The library will be installed and ready to use
Add to your platformio.ini:
lib_deps =
https://github.com/Vulintus/Vulintus_RGB_LED.git- Adafruit_NeoPixel (for NeoPixel support)
Connect LED pins to PWM-capable pins on your microcontroller:
- Red, Green, Blue channels (required)
- White channel (optional, for RGBW LEDs)
Connect NeoPixel data line to any digital output pin.
#include <Vulintus_RGB_LED.h>
// Define your LED pins
#define PIN_LED_R 9
#define PIN_LED_G 10
#define PIN_LED_B 11
// Create LED object
Vulintus_RGB_LED led(PIN_LED_R, PIN_LED_G, PIN_LED_B);
void setup() {
led.begin(); // Initialize the LED
led.set_rgb(255, 0, 0); // Set color to red
led.set_dur(1000); // Set duration to 1 second
led.light_on(); // Turn on the LED
}
void loop() {
led.timing_check(); // Check if LED should turn off
}#include <Vulintus_RGB_LED.h>
#define PIN_LED_R 9
#define PIN_LED_G 10
#define PIN_LED_B 11
#define PIN_LED_W 12
// Create RGBW LED object
Vulintus_RGB_LED led(PIN_LED_R, PIN_LED_G, PIN_LED_B, PIN_LED_W);
void setup() {
led.begin();
led.set_rgbw(0, 255, 0, 100); // Green with some white
led.set_dur(2000); // 2 second duration
led.light_on();
}
void loop() {
led.timing_check();
}#include <Vulintus_RGB_LED.h>
#include <Adafruit_NeoPixel.h>
#define PIN_NEOPIX 13
#define NUM_NEOPIX 1
// Create NeoPixel object
Adafruit_NeoPixel neopix = Adafruit_NeoPixel(NUM_NEOPIX, PIN_NEOPIX);
// Create LED controller for NeoPixel
Vulintus_RGB_LED led(&neopix, NUM_NEOPIX);
void setup() {
led.begin();
led.set_rgb(0, 0, 255); // Set to blue
led.light_on();
}
void loop() {
led.timing_check();
}#include <Vulintus_RGB_LED.h>
Vulintus_RGB_LED led(PIN_LED_R, PIN_LED_G, PIN_LED_B);
void setup() {
led.begin();
// Program multiple color/duration combinations
led.cur_stim = 0; // Select queue slot 0
led.set_rgb(255, 0, 0); // Red
led.set_dur(500); // 500ms
led.cur_stim = 1; // Select queue slot 1
led.set_rgb(0, 255, 0); // Green
led.set_dur(500);
led.cur_stim = 2; // Select queue slot 2
led.set_rgb(0, 0, 255); // Blue
led.set_dur(500);
}
void loop() {
// Cycle through the queue
for (uint8_t i = 0; i < 3; i++) {
led.light_on(i); // Turn on queue slot i
while (led.is_on) {
led.timing_check(); // Wait for auto-shutoff
}
delay(200); // Pause between flashes
}
}Create an LED controller for discrete RGB or RGBW LEDs.
- pin_r: Red LED pin
- pin_g: Green LED pin
- pin_b: Blue LED pin
- pin_w: White LED pin (optional, omit or use 0xFF for RGB-only)
Create an LED controller for NeoPixel LEDs.
- neopix_ptr: Pointer to initialized Adafruit_NeoPixel object
- num_neopix: Number of NeoPixels to control (default: 1)
Initialize the LED controller. Must be called in setup() before using other functions.
Turn on the LED using the currently selected stimulus from the queue.
Turn on the LED using a specific stimulus from the queue.
- queue_index: Index (0-5) of the stimulus to display
Immediately turn off the LED.
Check if the LED should automatically turn off based on the programmed duration. Call this regularly in loop().
Set the RGB color values (0-255) for the current stimulus.
Set the RGB color using a packed 32-bit integer.
Set the RGBW color values (0-255) for the current stimulus.
Set the RGBW color using a packed 32-bit integer.
Set the duration (in milliseconds) for the current stimulus. Use 65535 for infinite duration.
Set the LED control polarity.
- true: High signal turns LED on (default)
- false: Low signal turns LED on (inverted)
Current stimulus queue index (0-5). Set this to select which queue slot to program or display.
Status flag indicating whether the LED is currently on.
Array of stimulus parameters. Each element contains RGB/RGBW values and duration.
COLOR_RED // Index 0
COLOR_YELLOW // Index 1
COLOR_GREEN // Index 2
COLOR_CYAN // Index 3
COLOR_BLUE // Index 4
COLOR_MAGENTA // Index 5You can customize these defines before including the library:
#define LIGHT_QUEUE_SIZE 6 // Number of stimulus slots (default: 6)
#define STARTUP_STIM_DUR 100 // Default startup duration in ms (default: 100)
#include <Vulintus_RGB_LED.h>The library includes two example sketches:
- Vulintus_RGB_1LED_Test: Demonstrates single LED control with color cycling
- Vulintus_RGB_3LED_Test: Demonstrates control of multiple NeoPixels
Find these in File → Examples → Vulintus RGB LED Library in the Arduino IDE.
Copyright © 2025 Vulintus, Inc. All rights reserved.
See LICENSE file for details.
For questions, issues, or contributions:
- GitHub: https://github.com/Vulintus/Vulintus_RGB_LED
- Email: [email protected]
- Website: https://www.vulintus.com
- Initial release
- Separated from Vulintus_OmniTrak library
- Renamed from OmniTrak_RGB_LED to Vulintus_RGB_LED
- Support for discrete RGB/RGBW LEDs and NeoPixels
- Stimulus queue system with automatic timing