![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Bluetooth Connected TOF Sensor
Dependencies: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
bricks/blinker.cpp@28:def5e0f0fb06, 2017-02-01 (annotated)
- Committer:
- hux
- Date:
- Wed Feb 01 22:08:56 2017 +0000
- Revision:
- 28:def5e0f0fb06
First S16_Blue_ToF application which runs nicely!; Digital display can be switched on/off with red slider
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hux | 28:def5e0f0fb06 | 1 | // blinker.cpp - send a morse pattern to LED1 |
hux | 28:def5e0f0fb06 | 2 | // |
hux | 28:def5e0f0fb06 | 3 | // Function morse() is one way for running LED1 with a blinking sequence using |
hux | 28:def5e0f0fb06 | 4 | // a busy wait, until the sequence is completed. |
hux | 28:def5e0f0fb06 | 5 | // |
hux | 28:def5e0f0fb06 | 6 | // Blinker b; |
hux | 28:def5e0f0fb06 | 7 | // b.morse(" x xxx x "); send one time morse sequence, interval = 0.2 |
hux | 28:def5e0f0fb06 | 8 | // b.morse(" x xxx x ",0.5); send one time morse sequence, interval = 0.5 |
hux | 28:def5e0f0fb06 | 9 | // |
hux | 28:def5e0f0fb06 | 10 | // Function morse(o) got the additional feature to stop an ongoing timer based |
hux | 28:def5e0f0fb06 | 11 | // blinking sequence. |
hux | 28:def5e0f0fb06 | 12 | // |
hux | 28:def5e0f0fb06 | 13 | // The alternative is to setup an ever repeating blink sequence via LED1 using |
hux | 28:def5e0f0fb06 | 14 | // function blink(), which is non waiting. |
hux | 28:def5e0f0fb06 | 15 | // |
hux | 28:def5e0f0fb06 | 16 | // Blinker b; |
hux | 28:def5e0f0fb06 | 17 | // b.blink(" x xxx x "); repeating blink sequence, interval = 0.2 |
hux | 28:def5e0f0fb06 | 18 | // b.blink(" x xxx x ",0.5); repeating blink sequence, interval = 0.5 |
hux | 28:def5e0f0fb06 | 19 | // b.blink(); stops blinking sequence |
hux | 28:def5e0f0fb06 | 20 | // |
hux | 28:def5e0f0fb06 | 21 | |
hux | 28:def5e0f0fb06 | 22 | #include "bricks/target.h" |
hux | 28:def5e0f0fb06 | 23 | #include "bricks/blinker.h" |
hux | 28:def5e0f0fb06 | 24 | |
hux | 28:def5e0f0fb06 | 25 | #ifndef LED_INVERTED |
hux | 28:def5e0f0fb06 | 26 | # define LED_ON 1 |
hux | 28:def5e0f0fb06 | 27 | # define LED_OFF 0 |
hux | 28:def5e0f0fb06 | 28 | #else |
hux | 28:def5e0f0fb06 | 29 | # define LED_ON 0 |
hux | 28:def5e0f0fb06 | 30 | # define LED_OFF 1 |
hux | 28:def5e0f0fb06 | 31 | #endif |
hux | 28:def5e0f0fb06 | 32 | |
hux | 28:def5e0f0fb06 | 33 | #ifndef BLINK_LED |
hux | 28:def5e0f0fb06 | 34 | # define BLINK_LED LED1 |
hux | 28:def5e0f0fb06 | 35 | #endif |
hux | 28:def5e0f0fb06 | 36 | |
hux | 28:def5e0f0fb06 | 37 | static DigitalOut led(BLINK_LED); // being used for morse sequence |
hux | 28:def5e0f0fb06 | 38 | static Ticker ticker; // triggers periodic callbacks |
hux | 28:def5e0f0fb06 | 39 | static const char *pointer = 0; // 0 means morse activity disabled |
hux | 28:def5e0f0fb06 | 40 | static const char *sequence = 0; // next morse sequence for repeats |
hux | 28:def5e0f0fb06 | 41 | |
hux | 28:def5e0f0fb06 | 42 | void Blinker::stop() |
hux | 28:def5e0f0fb06 | 43 | { |
hux | 28:def5e0f0fb06 | 44 | pointer = 0; |
hux | 28:def5e0f0fb06 | 45 | sequence = 0; |
hux | 28:def5e0f0fb06 | 46 | } |
hux | 28:def5e0f0fb06 | 47 | |
hux | 28:def5e0f0fb06 | 48 | void Blinker::setled(bool state) |
hux | 28:def5e0f0fb06 | 49 | { |
hux | 28:def5e0f0fb06 | 50 | led = (state ? LED_ON : LED_OFF); |
hux | 28:def5e0f0fb06 | 51 | } |
hux | 28:def5e0f0fb06 | 52 | |
hux | 28:def5e0f0fb06 | 53 | void Blinker::morse(const char *pattern, double interval) |
hux | 28:def5e0f0fb06 | 54 | { |
hux | 28:def5e0f0fb06 | 55 | stop(); // stop current sequence |
hux | 28:def5e0f0fb06 | 56 | |
hux | 28:def5e0f0fb06 | 57 | for (; *pattern; pattern++) |
hux | 28:def5e0f0fb06 | 58 | { |
hux | 28:def5e0f0fb06 | 59 | setled(*pattern != ' '); |
hux | 28:def5e0f0fb06 | 60 | wait(interval); // busy waiting for interval time |
hux | 28:def5e0f0fb06 | 61 | } |
hux | 28:def5e0f0fb06 | 62 | } |
hux | 28:def5e0f0fb06 | 63 | |
hux | 28:def5e0f0fb06 | 64 | // callback for LED1 ticker controlled blinking |
hux | 28:def5e0f0fb06 | 65 | |
hux | 28:def5e0f0fb06 | 66 | static void cbBlinker(void) // blinker callback |
hux | 28:def5e0f0fb06 | 67 | { |
hux | 28:def5e0f0fb06 | 68 | if (pointer != 0) |
hux | 28:def5e0f0fb06 | 69 | { |
hux | 28:def5e0f0fb06 | 70 | if (*pointer == 0) |
hux | 28:def5e0f0fb06 | 71 | { |
hux | 28:def5e0f0fb06 | 72 | pointer = sequence; // reset pointer to followup sequence |
hux | 28:def5e0f0fb06 | 73 | } |
hux | 28:def5e0f0fb06 | 74 | |
hux | 28:def5e0f0fb06 | 75 | if (*pointer) |
hux | 28:def5e0f0fb06 | 76 | { |
hux | 28:def5e0f0fb06 | 77 | led = (*pointer++ == ' ') ? LED_OFF : LED_ON; |
hux | 28:def5e0f0fb06 | 78 | } |
hux | 28:def5e0f0fb06 | 79 | } |
hux | 28:def5e0f0fb06 | 80 | } |
hux | 28:def5e0f0fb06 | 81 | |
hux | 28:def5e0f0fb06 | 82 | void Blinker::blink(const char *pattern, const char* next, double interval) |
hux | 28:def5e0f0fb06 | 83 | { |
hux | 28:def5e0f0fb06 | 84 | pointer = 0; // stop current activities |
hux | 28:def5e0f0fb06 | 85 | led = LED_OFF; // reset led with LED_OFF |
hux | 28:def5e0f0fb06 | 86 | |
hux | 28:def5e0f0fb06 | 87 | sequence = next; // init morse sequence |
hux | 28:def5e0f0fb06 | 88 | |
hux | 28:def5e0f0fb06 | 89 | ticker.attach(cbBlinker,interval);// next LED state after every interval |
hux | 28:def5e0f0fb06 | 90 | pointer = pattern; // enable callback activty |
hux | 28:def5e0f0fb06 | 91 | } |
hux | 28:def5e0f0fb06 | 92 | |
hux | 28:def5e0f0fb06 | 93 | void Blinker::blink(const char *pattern, double interval) |
hux | 28:def5e0f0fb06 | 94 | { |
hux | 28:def5e0f0fb06 | 95 | blink(pattern,pattern,interval); |
hux | 28:def5e0f0fb06 | 96 | } |
hux | 28:def5e0f0fb06 | 97 | |
hux | 28:def5e0f0fb06 | 98 |