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:
Mon Apr 27 11:15:08 2015 +0000
Revision:
8:ddedf56b2eb0
Parent:
7:7abc04b4c474
Child:
9:b40252f5fee7
Pulsator::fun(): parametrise over intensity function.

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 6:5eeb1acc1c50 22 class Pulsator : Ticker
huliyang 0:dda7f6f55dc1 23 {
huliyang 0:dda7f6f55dc1 24 private:
huliyang 0:dda7f6f55dc1 25 PwmOut out;
huliyang 8:ddedf56b2eb0 26 float phase;
huliyang 0:dda7f6f55dc1 27
huliyang 6:5eeb1acc1c50 28 bool _active_high;
huliyang 6:5eeb1acc1c50 29 bool _enable;
huliyang 8:ddedf56b2eb0 30 float (*_fun)(float phase);
huliyang 6:5eeb1acc1c50 31 float _gamma;
huliyang 6:5eeb1acc1c50 32 float _period;
huliyang 6:5eeb1acc1c50 33 int _levels;
huliyang 0:dda7f6f55dc1 34
huliyang 5:26cc18306d95 35 void disable(void);
huliyang 0:dda7f6f55dc1 36 void enable(void);
huliyang 6:5eeb1acc1c50 37 void reload(void);
huliyang 5:26cc18306d95 38 void step(void);
huliyang 0:dda7f6f55dc1 39
huliyang 0:dda7f6f55dc1 40 public:
huliyang 6:5eeb1acc1c50 41 Pulsator(PinName pin = LED1);
huliyang 1:bcddb9898625 42 Pulsator& operator=(bool state);
huliyang 5:26cc18306d95 43 operator bool(void);
huliyang 6:5eeb1acc1c50 44
huliyang 6:5eeb1acc1c50 45 Pulsator& active_high(bool high = false);
huliyang 8:ddedf56b2eb0 46 Pulsator& fun(float (*fp)(float phase) = NULL);
huliyang 7:7abc04b4c474 47 Pulsator& gamma(float power = 2.2f);
huliyang 6:5eeb1acc1c50 48 Pulsator& levels(int number = 128);
huliyang 7:7abc04b4c474 49 Pulsator& period(float seconds = 1.0f);
huliyang 0:dda7f6f55dc1 50 };