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 03:56:51 2015 +0000
Revision:
0:dda7f6f55dc1
Child:
1:bcddb9898625
init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
huliyang 0:dda7f6f55dc1 1 #include <mbed.h>
huliyang 0:dda7f6f55dc1 2 #include <PwmOut.h>
huliyang 0:dda7f6f55dc1 3
huliyang 0:dda7f6f55dc1 4 class Pulsator
huliyang 0:dda7f6f55dc1 5 {
huliyang 0:dda7f6f55dc1 6 private:
huliyang 0:dda7f6f55dc1 7 PwmOut out;
huliyang 0:dda7f6f55dc1 8 Ticker ticker;
huliyang 0:dda7f6f55dc1 9 float phase_2; // phase / 2
huliyang 0:dda7f6f55dc1 10
huliyang 0:dda7f6f55dc1 11 const float period;
huliyang 0:dda7f6f55dc1 12 const bool active_high;
huliyang 0:dda7f6f55dc1 13 const float gamma;
huliyang 0:dda7f6f55dc1 14 const int levels;
huliyang 0:dda7f6f55dc1 15
huliyang 0:dda7f6f55dc1 16 void step(void);
huliyang 0:dda7f6f55dc1 17 void enable(void);
huliyang 0:dda7f6f55dc1 18 void disable(void);
huliyang 0:dda7f6f55dc1 19
huliyang 0:dda7f6f55dc1 20 public:
huliyang 0:dda7f6f55dc1 21 Pulsator(PinName pin = LED1, float period = 1.0, bool active_high = true, float gamma = 2.2, int levels = 32);
huliyang 0:dda7f6f55dc1 22 Pulsator& operator =(bool state);
huliyang 0:dda7f6f55dc1 23 };