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@3:9262b505d7a8, 2020-06-14 (annotated)
- Committer:
- Pythia
- Date:
- Sun Jun 14 20:35:55 2020 +0000
- Revision:
- 3:9262b505d7a8
- Parent:
- 1:1e448c750b63
Working version
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 | 1:1e448c750b63 | 6 | //#define L_CYCLE 2400 |
Pythia | 1:1e448c750b63 | 7 | #define L_CYCLE 1000 |
Pythia | 0:225e4447fdd3 | 8 | |
Pythia | 3:9262b505d7a8 | 9 | #define L_LED_OFF ((unsigned long int)(0.003*L_CYCLE)) |
Pythia | 1:1e448c750b63 | 10 | #define L_LED_ON ((unsigned long int)(0.100*L_CYCLE)) |
Pythia | 0:225e4447fdd3 | 11 | |
Pythia | 3:9262b505d7a8 | 12 | #define RAMP_SLOPE 2 |
Pythia | 3:9262b505d7a8 | 13 | #define ON_TIMEOUT 2000 |
Pythia | 0:225e4447fdd3 | 14 | |
Pythia | 0:225e4447fdd3 | 15 | |
Pythia | 0:225e4447fdd3 | 16 | class LED_line |
Pythia | 0:225e4447fdd3 | 17 | { |
Pythia | 0:225e4447fdd3 | 18 | public: |
Pythia | 0:225e4447fdd3 | 19 | LED_line ( const PinName led_pin, |
Pythia | 0:225e4447fdd3 | 20 | const unsigned long int led_min_in=L_LED_OFF, |
Pythia | 0:225e4447fdd3 | 21 | const unsigned long int led_max_in=L_LED_ON, |
Pythia | 0:225e4447fdd3 | 22 | const unsigned long int led_cycle_in=L_CYCLE, |
Pythia | 0:225e4447fdd3 | 23 | const bool mode=false ); |
Pythia | 0:225e4447fdd3 | 24 | void light(const unsigned int lenght=RAMP_SLOPE, const unsigned int timeout=ON_TIMEOUT); |
Pythia | 0:225e4447fdd3 | 25 | void dark(const unsigned int lenght=RAMP_SLOPE); |
Pythia | 0:225e4447fdd3 | 26 | inline void level(const unsigned long int led_level) {current_light = led_level; return; }; |
Pythia | 0:225e4447fdd3 | 27 | inline unsigned long int level(void) { return current_light; }; |
Pythia | 0:225e4447fdd3 | 28 | enum state_type {IDLE=0, UP, FULL, DOWN, DARK}; |
Pythia | 0:225e4447fdd3 | 29 | enum state_type state(void); |
Pythia | 0:225e4447fdd3 | 30 | void LED_run(void); |
Pythia | 0:225e4447fdd3 | 31 | ~LED_line(); |
Pythia | 0:225e4447fdd3 | 32 | private: |
Pythia | 0:225e4447fdd3 | 33 | inline int LED_PWM_F(const unsigned long int in) {return ((this->cnt < (in)) ? LED_ON : LED_OFF); }; |
Pythia | 0:225e4447fdd3 | 34 | inline int LED_PWM_B(const unsigned long int in) {return ((this->cnt > (this->led_cycle - (in))) ? LED_ON : LED_OFF); }; |
Pythia | 0:225e4447fdd3 | 35 | DigitalOut *led; |
Pythia | 0:225e4447fdd3 | 36 | const unsigned long int led_min; |
Pythia | 0:225e4447fdd3 | 37 | const unsigned long int led_max; |
Pythia | 0:225e4447fdd3 | 38 | const unsigned long int led_cycle; |
Pythia | 0:225e4447fdd3 | 39 | const bool led_mode; |
Pythia | 0:225e4447fdd3 | 40 | unsigned long int cnt; |
Pythia | 0:225e4447fdd3 | 41 | enum state_type state_value; |
Pythia | 0:225e4447fdd3 | 42 | unsigned int delta; |
Pythia | 0:225e4447fdd3 | 43 | unsigned int timeout; |
Pythia | 0:225e4447fdd3 | 44 | unsigned long int current_light; |
Pythia | 0:225e4447fdd3 | 45 | }; |
Pythia | 0:225e4447fdd3 | 46 |