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.
Pulsator.h@1:bcddb9898625, 2015-04-24 (annotated)
- Committer:
- huliyang
- Date:
- Fri Apr 24 05:14:06 2015 +0000
- Revision:
- 1:bcddb9898625
- Parent:
- 0:dda7f6f55dc1
- Child:
- 5:26cc18306d95
Doxygenate
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:dda7f6f55dc1 | 28 | |
huliyang | 0:dda7f6f55dc1 | 29 | const float period; |
huliyang | 0:dda7f6f55dc1 | 30 | const bool active_high; |
huliyang | 0:dda7f6f55dc1 | 31 | const float gamma; |
huliyang | 0:dda7f6f55dc1 | 32 | const int levels; |
huliyang | 0:dda7f6f55dc1 | 33 | |
huliyang | 0:dda7f6f55dc1 | 34 | void step(void); |
huliyang | 0:dda7f6f55dc1 | 35 | void enable(void); |
huliyang | 0:dda7f6f55dc1 | 36 | void disable(void); |
huliyang | 0:dda7f6f55dc1 | 37 | |
huliyang | 0:dda7f6f55dc1 | 38 | public: |
huliyang | 0:dda7f6f55dc1 | 39 | Pulsator(PinName pin = LED1, float period = 1.0, bool active_high = true, float gamma = 2.2, int levels = 32); |
huliyang | 1:bcddb9898625 | 40 | Pulsator& operator=(bool state); |
huliyang | 0:dda7f6f55dc1 | 41 | }; |