Use the hardware PwmOut to pulsate an LED (or something else), with selectable active high/low, customisable intensity function, gamma correction, and number of brightness levels.
Diff: Pulsator.cpp
- Revision:
- 5:26cc18306d95
- Parent:
- 4:55b287904199
- Child:
- 6:5eeb1acc1c50
--- a/Pulsator.cpp Fri Apr 24 07:58:22 2015 +0000 +++ b/Pulsator.cpp Fri Apr 24 21:26:05 2015 +0000 @@ -58,6 +58,7 @@ void Pulsator::enable(void) { + _enable = true; out.period(1.0 / 1024.0); phase_2 = 0.0; step(); @@ -66,6 +67,7 @@ void Pulsator::disable(void) { + _enable = false; ticker.detach(); out = active_high ? 0.0 : 1.0; } @@ -93,6 +95,12 @@ */ Pulsator& Pulsator::operator=(bool state) { - state ? enable() : disable(); + if(state != _enable) + state ? enable() : disable(); return *this; } + +Pulsator::operator bool(void) +{ + return _enable; +}