A nice BLE demo program which allows remote switch of an LED via GATT interface.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_Button by
bricks/blinker.h@12:0d0ca44397dd, 2017-10-21 (annotated)
- Committer:
- hux
- Date:
- Sat Oct 21 19:55:47 2017 +0000
- Revision:
- 12:0d0ca44397dd
A nice BLE demo program which allows to switch a LED via BLE GATT interface.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 12:0d0ca44397dd | 1 | // blinker.h - blinking sequences for LED1 |
hux | 12:0d0ca44397dd | 2 | #ifndef _BLINKER_H_ |
hux | 12:0d0ca44397dd | 3 | #define _BLINKER_H_ |
hux | 12:0d0ca44397dd | 4 | |
hux | 12:0d0ca44397dd | 5 | #include <mbed.h> |
hux | 12:0d0ca44397dd | 6 | |
hux | 12:0d0ca44397dd | 7 | # define BLINKER_SEQUENCE_IDLE "x " |
hux | 12:0d0ca44397dd | 8 | # define BLINKER_SEQUENCE_ADVERTISE "x xxx " |
hux | 12:0d0ca44397dd | 9 | # define BLINKER_SEQUENCE_CONNECTED " xxx " |
hux | 12:0d0ca44397dd | 10 | # define BLINKER_SEQUENCE_ACTION "x x x x x " |
hux | 12:0d0ca44397dd | 11 | # define BLINKER_SEQUENCE_ERROR "x x x x xxx " |
hux | 12:0d0ca44397dd | 12 | # define BLINKER_SEQUENCE_TRANSITION "x x x " |
hux | 12:0d0ca44397dd | 13 | |
hux | 12:0d0ca44397dd | 14 | class Blinker |
hux | 12:0d0ca44397dd | 15 | { |
hux | 12:0d0ca44397dd | 16 | public: // construction |
hux | 12:0d0ca44397dd | 17 | Blinker() {} // nothing to do |
hux | 12:0d0ca44397dd | 18 | |
hux | 12:0d0ca44397dd | 19 | public: |
hux | 12:0d0ca44397dd | 20 | void morse(const char *pattern, double periode = 0.2); |
hux | 12:0d0ca44397dd | 21 | void blink(const char *pattern, const char* next, double interval = 0.2); |
hux | 12:0d0ca44397dd | 22 | void blink(const char *pattern, double periode = 0.2); |
hux | 12:0d0ca44397dd | 23 | |
hux | 12:0d0ca44397dd | 24 | void idle(const char *action = BLINKER_SEQUENCE_IDLE) |
hux | 12:0d0ca44397dd | 25 | { |
hux | 12:0d0ca44397dd | 26 | blink(action,BLINKER_SEQUENCE_IDLE); |
hux | 12:0d0ca44397dd | 27 | } |
hux | 12:0d0ca44397dd | 28 | |
hux | 12:0d0ca44397dd | 29 | void advertise(const char *action = BLINKER_SEQUENCE_ADVERTISE) |
hux | 12:0d0ca44397dd | 30 | { |
hux | 12:0d0ca44397dd | 31 | blink(action,BLINKER_SEQUENCE_ADVERTISE); |
hux | 12:0d0ca44397dd | 32 | } |
hux | 12:0d0ca44397dd | 33 | |
hux | 12:0d0ca44397dd | 34 | void connected(const char *action = BLINKER_SEQUENCE_ACTION) |
hux | 12:0d0ca44397dd | 35 | { |
hux | 12:0d0ca44397dd | 36 | blink(action, BLINKER_SEQUENCE_CONNECTED); |
hux | 12:0d0ca44397dd | 37 | } |
hux | 12:0d0ca44397dd | 38 | |
hux | 12:0d0ca44397dd | 39 | void action() // 'action' blink sequence |
hux | 12:0d0ca44397dd | 40 | { |
hux | 12:0d0ca44397dd | 41 | blink(BLINKER_SEQUENCE_ACTION, BLINKER_SEQUENCE_IDLE); |
hux | 12:0d0ca44397dd | 42 | } |
hux | 12:0d0ca44397dd | 43 | |
hux | 12:0d0ca44397dd | 44 | void blinkError(const char *action = BLINKER_SEQUENCE_ERROR) |
hux | 12:0d0ca44397dd | 45 | { |
hux | 12:0d0ca44397dd | 46 | blink(action,BLINKER_SEQUENCE_ERROR); |
hux | 12:0d0ca44397dd | 47 | } |
hux | 12:0d0ca44397dd | 48 | |
hux | 12:0d0ca44397dd | 49 | void blink() // stop blinking |
hux | 12:0d0ca44397dd | 50 | { |
hux | 12:0d0ca44397dd | 51 | blink(""); // empty blinking pattern |
hux | 12:0d0ca44397dd | 52 | } |
hux | 12:0d0ca44397dd | 53 | }; |
hux | 12:0d0ca44397dd | 54 | |
hux | 12:0d0ca44397dd | 55 | #endif // _BLINKER_H_ |