Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: tsi_sensor MMA8451Q
LED_line.h@0:225e4447fdd3, 2020-06-07 (annotated)
- Committer:
- Pythia
- Date:
- Sun Jun 07 19:50:51 2020 +0000
- Revision:
- 0:225e4447fdd3
- Child:
- 1:1e448c750b63
LED PWM on FRDM with no usage of the mBed PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pythia | 0:225e4447fdd3 | 1 | #include "mbed.h" |
Pythia | 0:225e4447fdd3 | 2 | |
Pythia | 0:225e4447fdd3 | 3 | #define LED_OFF 1 |
Pythia | 0:225e4447fdd3 | 4 | #define LED_ON 0 |
Pythia | 0:225e4447fdd3 | 5 | |
Pythia | 0:225e4447fdd3 | 6 | #define L_CYCLE 2400 |
Pythia | 0:225e4447fdd3 | 7 | |
Pythia | 0:225e4447fdd3 | 8 | #define L_LED_OFF ((unsigned long int)(0.01*L_CYCLE)) |
Pythia | 0:225e4447fdd3 | 9 | #define L_LED_ON ((unsigned long int)(0.99*L_CYCLE)) |
Pythia | 0:225e4447fdd3 | 10 | |
Pythia | 0:225e4447fdd3 | 11 | #define RAMP_SLOPE 50 |
Pythia | 0:225e4447fdd3 | 12 | #define ON_TIMEOUT 500 |
Pythia | 0:225e4447fdd3 | 13 | |
Pythia | 0:225e4447fdd3 | 14 | |
Pythia | 0:225e4447fdd3 | 15 | class LED_line |
Pythia | 0:225e4447fdd3 | 16 | { |
Pythia | 0:225e4447fdd3 | 17 | public: |
Pythia | 0:225e4447fdd3 | 18 | LED_line ( const PinName led_pin, |
Pythia | 0:225e4447fdd3 | 19 | const unsigned long int led_min_in=L_LED_OFF, |
Pythia | 0:225e4447fdd3 | 20 | const unsigned long int led_max_in=L_LED_ON, |
Pythia | 0:225e4447fdd3 | 21 | const unsigned long int led_cycle_in=L_CYCLE, |
Pythia | 0:225e4447fdd3 | 22 | const bool mode=false ); |
Pythia | 0:225e4447fdd3 | 23 | void light(const unsigned int lenght=RAMP_SLOPE, const unsigned int timeout=ON_TIMEOUT); |
Pythia | 0:225e4447fdd3 | 24 | void dark(const unsigned int lenght=RAMP_SLOPE); |
Pythia | 0:225e4447fdd3 | 25 | inline void level(const unsigned long int led_level) {current_light = led_level; return; }; |
Pythia | 0:225e4447fdd3 | 26 | inline unsigned long int level(void) { return current_light; }; |
Pythia | 0:225e4447fdd3 | 27 | enum state_type {IDLE=0, UP, FULL, DOWN, DARK}; |
Pythia | 0:225e4447fdd3 | 28 | enum state_type state(void); |
Pythia | 0:225e4447fdd3 | 29 | void LED_run(void); |
Pythia | 0:225e4447fdd3 | 30 | ~LED_line(); |
Pythia | 0:225e4447fdd3 | 31 | private: |
Pythia | 0:225e4447fdd3 | 32 | inline int LED_PWM_F(const unsigned long int in) {return ((this->cnt < (in)) ? LED_ON : LED_OFF); }; |
Pythia | 0:225e4447fdd3 | 33 | inline int LED_PWM_B(const unsigned long int in) {return ((this->cnt > (this->led_cycle - (in))) ? LED_ON : LED_OFF); }; |
Pythia | 0:225e4447fdd3 | 34 | DigitalOut *led; |
Pythia | 0:225e4447fdd3 | 35 | const unsigned long int led_min; |
Pythia | 0:225e4447fdd3 | 36 | const unsigned long int led_max; |
Pythia | 0:225e4447fdd3 | 37 | const unsigned long int led_cycle; |
Pythia | 0:225e4447fdd3 | 38 | const bool led_mode; |
Pythia | 0:225e4447fdd3 | 39 | unsigned long int cnt; |
Pythia | 0:225e4447fdd3 | 40 | enum state_type state_value; |
Pythia | 0:225e4447fdd3 | 41 | unsigned int delta; |
Pythia | 0:225e4447fdd3 | 42 | unsigned int timeout; |
Pythia | 0:225e4447fdd3 | 43 | unsigned long int current_light; |
Pythia | 0:225e4447fdd3 | 44 | }; |
Pythia | 0:225e4447fdd3 | 45 |