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@7:7abc04b4c474, 2015-04-26 (annotated)
- Committer:
- huliyang
- Date:
- Sun Apr 26 01:43:31 2015 +0000
- Revision:
- 7:7abc04b4c474
- Parent:
- 6:5eeb1acc1c50
- Child:
- 8:ddedf56b2eb0
float constants
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 | 6:5eeb1acc1c50 | 22 | class Pulsator : Ticker |
huliyang | 0:dda7f6f55dc1 | 23 | { |
huliyang | 0:dda7f6f55dc1 | 24 | private: |
huliyang | 0:dda7f6f55dc1 | 25 | PwmOut out; |
huliyang | 1:bcddb9898625 | 26 | float phase_2; //!< \a phase / 2 |
huliyang | 0:dda7f6f55dc1 | 27 | |
huliyang | 6:5eeb1acc1c50 | 28 | bool _active_high; |
huliyang | 6:5eeb1acc1c50 | 29 | bool _enable; |
huliyang | 6:5eeb1acc1c50 | 30 | float _gamma; |
huliyang | 6:5eeb1acc1c50 | 31 | float _period; |
huliyang | 6:5eeb1acc1c50 | 32 | int _levels; |
huliyang | 0:dda7f6f55dc1 | 33 | |
huliyang | 5:26cc18306d95 | 34 | void disable(void); |
huliyang | 0:dda7f6f55dc1 | 35 | void enable(void); |
huliyang | 6:5eeb1acc1c50 | 36 | void reload(void); |
huliyang | 5:26cc18306d95 | 37 | void step(void); |
huliyang | 0:dda7f6f55dc1 | 38 | |
huliyang | 0:dda7f6f55dc1 | 39 | public: |
huliyang | 6:5eeb1acc1c50 | 40 | Pulsator(PinName pin = LED1); |
huliyang | 1:bcddb9898625 | 41 | Pulsator& operator=(bool state); |
huliyang | 5:26cc18306d95 | 42 | operator bool(void); |
huliyang | 6:5eeb1acc1c50 | 43 | |
huliyang | 6:5eeb1acc1c50 | 44 | Pulsator& active_high(bool high = false); |
huliyang | 7:7abc04b4c474 | 45 | Pulsator& gamma(float power = 2.2f); |
huliyang | 6:5eeb1acc1c50 | 46 | Pulsator& levels(int number = 128); |
huliyang | 7:7abc04b4c474 | 47 | Pulsator& period(float seconds = 1.0f); |
huliyang | 0:dda7f6f55dc1 | 48 | }; |