This is a LED library for Arduino. It provides everyday tasks like on/off, fade, blink, ...
This library is ESP32 compatible now. Be aware there's no LED fade capability.
- 2014-01-15 Initial release
- 2016-05-14 Prevent LED from turning off when fading
- 2018-12-06 ESP32 analogWrite fix
- 2019-02-23 prevent led from flickering when fading in/out again
- 2021-09-30 fix compile errors
Download the ZIP file and extract its content. Move the TTLED folder to "ARDUINOAPP/hardware/libraries/". In the Arduino IDE you'll find the sample sketches under Samples->TTLED.
pin: the number of the pin which is attached to the LED
activeHigh: true, false. true: digital pin is attached to LED's anode. false: digital pin is attached to LED's cathode
nothing
TTLED led = TTLED(5, true);
This method must be called. It initialises the LED pin.
none
nothing
led.init();
This method turns the attached LED on. All async modes will be stopped.
none
nothing
led.on();
This method turns the attached LED off. All async modes will be stopped.
none
nothing
led.off();
This method returns the logical state of the LED. It will be LOW if LED is fully off. It will be HIGH if LED fully or partially on.
none
HIGH/LOW
if(led.getState() == HIGH){
//code if led is on
}
else{
//code if led is fully off
}
This method returns the current brightness (0-255) of the LED.
none
uint8_t 0 - 255 (0=off, 255 = full brightness)
int brightness = led.getValue();
Turns the LED on if it's off. Turns the LED off if it's on.
none
nothing
led.toggle();
Stops the LED's async mode. Async mode gets started by calling blinkAsync() or fadeAsync().
none
nothing
led.stopAsync();
Starts the auto blinking mode. Ensure to call the update() method continuously. If you don't call it, the LED will not blink.
blinkInterval: LED is on for blinkInterval ms and off for blinkInterval ms
nothing
led.blinkAsync(1000);
void loop(){
led.update();
}
Starts the auto blinking mode with different on/off times. Ensure to call the update() method continuously. If you don't call it, the LED will not blink.
onInterval: LED is on for onInterval ms offInterval: LED is off for offInterval ms
nothing
led.blinkAsync(10, 990); //LED blinks every second for 10ms
void loop(){
led.update();
}
Blinks the LED n times. Blinking is not done asynchronously. This means, your sketch will stop until blinking is done.
blinkInterval: LED is on for blinkInterval ms and off for blinkInterval ms times: Blinking gets repeated n times.
nothing
led.blink(1000, 5);
Starts fading the LED. Fadin is based on an internal ease in/out algorithm. Ensure to call the update() method continuously. If you don't call it, the LED will not fade.
time: Time in ms for one full fade period (in and out)
nothing
led.fadeAsync(1000);
void loop(){
led.update();
}
Fades the LED in (from current brightness to max brightness).
fadeTime: Time in ms for fading in
nothing
led.fadeIn(1000);
Fades the LED out (from current brightness to dark).
fadeTime: Time in ms for fading out
nothing
led.fadeOut(1000);
Sets the LED's PWM value. It is the same as analogWrite();
value: 0 - 255 (0=off, 255 = full brightness)
nothing
led.setValue(150);
Sets the allowed maximum brightness of the LED. For example the method on() will take this maximum brightness value. If max value is set to 0, the LED is off, but it is working like brightness was set to 255. This means, you can still get virtually the on/off state.
value: 0 - 255 (0=off, 255 = full brightness)
nothing
led.setMaxValue(200);