modm API documentation
modm::ui::Led Class Reference

#include <modm/ui/led/led.hpp>

Public Member Functions

 Led (Animation< uint8_t >::Handler handler)
 Requires a handler function pointer for value updates.
 
void setBrightness (uint8_t brightness)
 
uint8_t getBrightness () const
 
bool isFading () const
 
void fadeTo (uint8_t brightness, uint16_t time)
 
void on (uint16_t time=75)
 
void off (uint16_t time=120)
 
void update ()
 
 operator Animation< uint8_t > & ()
 This object can be cast to the underlying Animation object.
 

Detailed Description

This class supplies a basic interface to fade an LED to any brightness level. A lookup-table should be used to store the alpha corrected PWM values, so that no calculation has to be done at run time.

Here is an example for the STM32F4:

#include <modm/ui/led.hpp>
// use a lambda function without a closure, this is equivalent to a normal function pointer
modm::ui::Led orange([](uint8_t brightness)
{
Timer4::setCompareValue(2, modm::ui::table22_16_256[brightness]);
});
// setup Timer4 etc...

This is just a very, very thin wrapper around modm::ui::Animation<uint8_t>. If you need more advanced features, have a look there.

See also
Animators
Author
Niklas Hauser

Member Function Documentation

void modm::ui::Led::fadeTo ( uint8_t  brightness,
uint16_t  time 
)
inline

Fade from the current brightness to a new brightness in the specified ms. Fading times of more than ~32s are not possible. You must control fading externally in that case.

uint8_t modm::ui::Led::getBrightness ( ) const
inline
Returns
brightness of the LED
bool modm::ui::Led::isFading ( ) const
inline
Returns
true if LED is currently fading to another brightness, false if otherwise
void modm::ui::Led::off ( uint16_t  time = 120)
inline

Mimics the behavior of normal lamps, which take a small amount of time until fully extinguished.

Parameters
timespecify the fade up time in ms, 0 to turn the LED off instantly
void modm::ui::Led::on ( uint16_t  time = 75)
inline

Mimics the behavior of normal lamps, which take a small amount of time until achieving full brightness.

Parameters
timespecify the fade up time in ms, 0 to turn the LED on instantly
void modm::ui::Led::setBrightness ( uint8_t  brightness)
inline
Parameters
brightnessbetween 0 and length of lookup-table (usually 255)
void modm::ui::Led::update ( )
inline

Can be called at a interval of 1ms or less. If you do not need 1ms response time (e.g. for on(), off()), you may call this at intervals < 255ms.


The documentation for this class was generated from the following file: