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@9:b40252f5fee7, 2015-04-28 (annotated)
- Committer:
- huliyang
- Date:
- Tue Apr 28 15:42:25 2015 +0000
- Revision:
- 9:b40252f5fee7
- Parent:
- 8:ddedf56b2eb0
- Child:
- 10:1ade8e824939
Reflow license text.
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 | 9:b40252f5fee7 | 3 | * Permission is hereby granted, free of charge, to any person obtaining |
huliyang | 9:b40252f5fee7 | 4 | * a copy of this software and associated documentation files (the |
huliyang | 9:b40252f5fee7 | 5 | * "Software"), to deal in the Software without restriction, including |
huliyang | 9:b40252f5fee7 | 6 | * without limitation the rights to use, copy, modify, merge, publish, |
huliyang | 9:b40252f5fee7 | 7 | * distribute, sublicense, and/or sell copies of the Software, and to |
huliyang | 9:b40252f5fee7 | 8 | * permit persons to whom the Software is furnished to do so, subject to |
huliyang | 9:b40252f5fee7 | 9 | * the following conditions: |
huliyang | 1:bcddb9898625 | 10 | * |
huliyang | 9:b40252f5fee7 | 11 | * The above copyright notice and this permission notice shall be |
huliyang | 9:b40252f5fee7 | 12 | * included in all copies or substantial portions of the Software. |
huliyang | 1:bcddb9898625 | 13 | * |
huliyang | 9:b40252f5fee7 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
huliyang | 9:b40252f5fee7 | 15 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
huliyang | 9:b40252f5fee7 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
huliyang | 9:b40252f5fee7 | 17 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
huliyang | 9:b40252f5fee7 | 18 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
huliyang | 9:b40252f5fee7 | 19 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
huliyang | 9:b40252f5fee7 | 20 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
huliyang | 1:bcddb9898625 | 21 | */ |
huliyang | 1:bcddb9898625 | 22 | |
huliyang | 0:dda7f6f55dc1 | 23 | #include <mbed.h> |
huliyang | 0:dda7f6f55dc1 | 24 | #include <PwmOut.h> |
huliyang | 0:dda7f6f55dc1 | 25 | |
huliyang | 6:5eeb1acc1c50 | 26 | class Pulsator : Ticker |
huliyang | 0:dda7f6f55dc1 | 27 | { |
huliyang | 0:dda7f6f55dc1 | 28 | private: |
huliyang | 0:dda7f6f55dc1 | 29 | PwmOut out; |
huliyang | 8:ddedf56b2eb0 | 30 | float phase; |
huliyang | 0:dda7f6f55dc1 | 31 | |
huliyang | 6:5eeb1acc1c50 | 32 | bool _active_high; |
huliyang | 6:5eeb1acc1c50 | 33 | bool _enable; |
huliyang | 8:ddedf56b2eb0 | 34 | float (*_fun)(float phase); |
huliyang | 6:5eeb1acc1c50 | 35 | float _gamma; |
huliyang | 6:5eeb1acc1c50 | 36 | float _period; |
huliyang | 6:5eeb1acc1c50 | 37 | int _levels; |
huliyang | 0:dda7f6f55dc1 | 38 | |
huliyang | 5:26cc18306d95 | 39 | void disable(void); |
huliyang | 0:dda7f6f55dc1 | 40 | void enable(void); |
huliyang | 6:5eeb1acc1c50 | 41 | void reload(void); |
huliyang | 5:26cc18306d95 | 42 | void step(void); |
huliyang | 0:dda7f6f55dc1 | 43 | |
huliyang | 0:dda7f6f55dc1 | 44 | public: |
huliyang | 6:5eeb1acc1c50 | 45 | Pulsator(PinName pin = LED1); |
huliyang | 1:bcddb9898625 | 46 | Pulsator& operator=(bool state); |
huliyang | 5:26cc18306d95 | 47 | operator bool(void); |
huliyang | 6:5eeb1acc1c50 | 48 | |
huliyang | 6:5eeb1acc1c50 | 49 | Pulsator& active_high(bool high = false); |
huliyang | 8:ddedf56b2eb0 | 50 | Pulsator& fun(float (*fp)(float phase) = NULL); |
huliyang | 7:7abc04b4c474 | 51 | Pulsator& gamma(float power = 2.2f); |
huliyang | 6:5eeb1acc1c50 | 52 | Pulsator& levels(int number = 128); |
huliyang | 7:7abc04b4c474 | 53 | Pulsator& period(float seconds = 1.0f); |
huliyang | 0:dda7f6f55dc1 | 54 | }; |