J&W / Mbed OS frdm_LED_PWM

Dependencies:   tsi_sensor MMA8451Q

LED_line.h

Committer:
Pythia
Date:
2020-06-07
Revision:
0:225e4447fdd3
Child:
1:1e448c750b63

File content as of revision 0:225e4447fdd3:

#include "mbed.h"

#define LED_OFF 1
#define LED_ON 0

#define L_CYCLE 2400

#define L_LED_OFF ((unsigned long int)(0.01*L_CYCLE))
#define L_LED_ON ((unsigned long int)(0.99*L_CYCLE))

#define RAMP_SLOPE 50
#define ON_TIMEOUT 500


class LED_line 
{
public:
    LED_line (  const PinName led_pin, 
                const unsigned long int led_min_in=L_LED_OFF, 
                const unsigned long int led_max_in=L_LED_ON, 
                const unsigned long int led_cycle_in=L_CYCLE, 
                const bool mode=false );
    void light(const unsigned int lenght=RAMP_SLOPE, const unsigned int timeout=ON_TIMEOUT);
    void dark(const unsigned int lenght=RAMP_SLOPE);
    inline void level(const unsigned long int led_level) {current_light = led_level; return; };
    inline unsigned long int level(void) { return current_light; };
    enum state_type {IDLE=0, UP, FULL, DOWN, DARK};
    enum state_type state(void);
    void LED_run(void);
    ~LED_line();
private:
    inline int LED_PWM_F(const unsigned long int in) {return ((this->cnt < (in)) ? LED_ON : LED_OFF); };
    inline int LED_PWM_B(const unsigned long int in) {return ((this->cnt > (this->led_cycle - (in))) ? LED_ON : LED_OFF); };
    DigitalOut *led;
    const unsigned long int led_min;
    const unsigned long int led_max;
    const unsigned long int led_cycle;
    const bool led_mode;
    unsigned long int cnt;
    enum state_type state_value;
    unsigned int delta;
    unsigned int timeout;
    unsigned long int current_light;
};