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.

Dependents:   RedButton

Committer:
huliyang
Date:
Fri Apr 24 21:26:05 2015 +0000
Revision:
5:26cc18306d95
Parent:
1:bcddb9898625
Child:
6:5eeb1acc1c50
Pulsator& Pulsator::operator=(bool): idempotentcy; ; * Also, query current state via Pulsator::operator bool()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
huliyang 1:bcddb9898625 1 /* Copyright (c) 2015 Liyang HU, MIT License
huliyang 1:bcddb9898625 2 *
huliyang 1:bcddb9898625 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
huliyang 1:bcddb9898625 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
huliyang 1:bcddb9898625 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
huliyang 1:bcddb9898625 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
huliyang 1:bcddb9898625 7 * furnished to do so, subject to the following conditions:
huliyang 1:bcddb9898625 8 *
huliyang 1:bcddb9898625 9 * The above copyright notice and this permission notice shall be included in all copies or
huliyang 1:bcddb9898625 10 * substantial portions of the Software.
huliyang 1:bcddb9898625 11 *
huliyang 1:bcddb9898625 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
huliyang 1:bcddb9898625 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
huliyang 1:bcddb9898625 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
huliyang 1:bcddb9898625 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
huliyang 1:bcddb9898625 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
huliyang 1:bcddb9898625 17 */
huliyang 1:bcddb9898625 18
huliyang 0:dda7f6f55dc1 19 #include <mbed.h>
huliyang 0:dda7f6f55dc1 20 #include <PwmOut.h>
huliyang 0:dda7f6f55dc1 21
huliyang 0:dda7f6f55dc1 22 class Pulsator
huliyang 0:dda7f6f55dc1 23 {
huliyang 0:dda7f6f55dc1 24 private:
huliyang 0:dda7f6f55dc1 25 PwmOut out;
huliyang 0:dda7f6f55dc1 26 Ticker ticker;
huliyang 1:bcddb9898625 27 float phase_2; //!< \a phase / 2
huliyang 5:26cc18306d95 28 bool _enable;
huliyang 0:dda7f6f55dc1 29
huliyang 0:dda7f6f55dc1 30 const float period;
huliyang 0:dda7f6f55dc1 31 const bool active_high;
huliyang 0:dda7f6f55dc1 32 const float gamma;
huliyang 0:dda7f6f55dc1 33 const int levels;
huliyang 0:dda7f6f55dc1 34
huliyang 5:26cc18306d95 35 void disable(void);
huliyang 0:dda7f6f55dc1 36 void enable(void);
huliyang 5:26cc18306d95 37 void step(void);
huliyang 0:dda7f6f55dc1 38
huliyang 0:dda7f6f55dc1 39 public:
huliyang 0:dda7f6f55dc1 40 Pulsator(PinName pin = LED1, float period = 1.0, bool active_high = true, float gamma = 2.2, int levels = 32);
huliyang 1:bcddb9898625 41 Pulsator& operator=(bool state);
huliyang 5:26cc18306d95 42 operator bool(void);
huliyang 0:dda7f6f55dc1 43 };