Built and maintained by Imogen Wren on behalf of Pan Galactic Tech
- Object Orientated library for controling single LEDs.
- Seperate class defintions for "blink" (digital) and "fade" (PWM) LED outputs.
- Set up LED blink & fade behaviour without dealing with any delay() functions and the problems this causes.
- fadeLED inherets all functions from ledObject (blink) LEDs.
- Call blink or fade events which count down a specific number of ledEvents before ending.
- Set up blinks and fades that continue until stop method is called.
- Functions work with both AVR (ATmega) / Arduino Boards & ESP32/8266 Espressif Microcontrollers.
- Call as many constructors as needed, each one controls a single LED, but many can be stacked and accessed as object arrays.
- Clone or Download library folder into Arduino IDE libraries folder.
- Extract files from zipped folder if required.
- Open Arduino IDE and select from example programs.
No dependency for library function, however examples have the following dependencies:
- autoDelay_library available from here - written by PanGalacticTech
#include <ledObject.h> // Libary include N.B.This includes both ledObject & fadeLED classes
Define the LED pin and the initial state.
#define LED_PIN 9 // Define LED pin. If undefined - defaults to pin 13.
#define INITIAL_STATE 1 // Defines if LED pin starts with initial state ON or OFF - defaults to OFF
For ESP32 & espressif boards, additional variables are required for setup.
#define PWM_PIN 2 // PWM drive capable pin
#define LED_CH 0 // PWM Channel (ESP32 up to 16 channels total)
#define PWM_FREQ 5000 // PWM Frequency (Hz)
#define PWM_RESO 8 // PWM Resolution (bits)
Declaring a blink LED object:
ledObject led(LED_PIN)
Declaring a fade LED object:
fadeLED led(LED_PIN); // Note: LED_PIN must be PWM capable pin
Declaring a fade LED object:
fadeLED led(PWM_PIN, LED_CH, PWM_FREQ, PWM_RESO); // ESP32 Requires 4 arguments for constructor
Setup function for Blink LEDs pass the initial state as an argument. Defaults to off.
led.begin(INITIAL_STATE);
Setup function for Fade LEDs pass the initial brightness as an argument. Default is 150
led.begin(INITIAL_BRIGHTNESS);
Call performBlink() or PerformFade(); on LED objects to set the output pins. This method should be called in main loop for each ledObject or fadeLED object.
For blink objects
led.performBlink();
For fade objects
led.performFade();
Note: performBlink(); and performFade(); are both valid for fadeLED objects, performFade will also carry out any Blink events triggered. Fading events take priority over Blink events if they are called together.
performFade(); is not valid for ledObjects.
Blink & Fade events must be triggered to be performed.
Start a Blink event that continues indefinatly:
led.startBlink(onDuration, offDuration);
Call a Blink event that repeats a number of times:
led.blinkEvent(numberofBlinks, onDuration, offDuration );
Start a Fade event that continues indefinatly:
led.startFading(minBrightness, maxBrightness , timeMs); // timeMs is time for complete fade (Up & Down)
Call a Fade event that repeats a number of times:
led.fadeEvent(minimum , maximum, repeats, timeMs = 500);
_____
To stop a blink event call:
led.stopBlink();
To stop a fade event call:
led.stopFading();
See star_trek_flash_board to see these techniques in action.
Set up arrays of ledObject and fadeLED constructors to iterate through large numbers of outputs easily.
ledObject flash[6] = {ledObject(2), ledObject(4), ledObject(7), ledObject(8), ledObject(12), ledObject(13)};
// Set up an array of ledObjects, each ledObject is passed an output pin
fadeLED fade[6] = {fadeLED(3), fadeLED(5), fadeLED(6), fadeLED(9), fadeLED(10), fadeLED(11)};
// Set up an array of fadeLEDs. Each LED is passed a PWM capable output pin
Iterate through object array using a for loop for setup functions.
for (int i = 0; i < NUM_FLASHERS; i++) {
flash[i].begin(INITIAL_STATE);
}
Iterate through object array using a for loop to start or change flashing/fading behaviour.
for (int i = 0; i < NUM_FADERS; i++) {
fade[i].startFading(0, 255, random(1, 1000)); // feed new random numbers into the fade objects
}
Iterate through object array with perform function (Must be called in every loop).
for (int i = 0; i < NUM_FADERS; i++) {
fade[i].performFades(); // PerformFade events, also performs blink events.
}
- Please report any bugs or issues found.
- Please report any bugs or issues found.
- Arduino IDE - Default IDE