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 Bluetooth Low Energy

Committer:
hux
Date:
Sat Oct 21 19:56:15 2017 +0000
Revision:
13:0563f1aa6a75
Parent:
12:0d0ca44397dd
Switch LED via BLE GATT

Who changed what in which revision?

UserRevisionLine numberNew 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_