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.h
- Revision:
- 6:5eeb1acc1c50
- Parent:
- 5:26cc18306d95
- Child:
- 7:7abc04b4c474
--- a/Pulsator.h Fri Apr 24 21:26:05 2015 +0000 +++ b/Pulsator.h Sun Apr 26 01:39:38 2015 +0000 @@ -19,25 +19,30 @@ #include <mbed.h> #include <PwmOut.h> -class Pulsator +class Pulsator : Ticker { private: PwmOut out; - Ticker ticker; float phase_2; //!< \a phase / 2 - bool _enable; - const float period; - const bool active_high; - const float gamma; - const int levels; + bool _active_high; + bool _enable; + float _gamma; + float _period; + int _levels; void disable(void); void enable(void); + void reload(void); void step(void); public: - Pulsator(PinName pin = LED1, float period = 1.0, bool active_high = true, float gamma = 2.2, int levels = 32); + Pulsator(PinName pin = LED1); Pulsator& operator=(bool state); operator bool(void); + + Pulsator& active_high(bool high = false); + Pulsator& gamma(float power = 2.2); + Pulsator& levels(int number = 128); + Pulsator& period(float seconds = 1.0); };