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: BLE_API X_NUCLEO_6180XA1 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
blinker.cpp
00001 // blinker.cpp - send a morse pattern to LED1 00002 // 00003 // Function morse() is one way for running LED1 with a blinking sequence using 00004 // a busy wait, until the sequence is completed. 00005 // 00006 // Blinker b; 00007 // b.morse(" x xxx x "); send one time morse sequence, interval = 0.2 00008 // b.morse(" x xxx x ",0.5); send one time morse sequence, interval = 0.5 00009 // 00010 // Function morse(o) got the additional feature to stop an ongoing timer based 00011 // blinking sequence. 00012 // 00013 // The alternative is to setup an ever repeating blink sequence via LED1 using 00014 // function blink(), which is non waiting. 00015 // 00016 // Blinker b; 00017 // b.blink(" x xxx x "); repeating blink sequence, interval = 0.2 00018 // b.blink(" x xxx x ",0.5); repeating blink sequence, interval = 0.5 00019 // b.blink(); stops blinking sequence 00020 // 00021 00022 #include "bricks/target.h" 00023 #include "bricks/blinker.h" 00024 00025 #ifndef LED_INVERTED 00026 # define LED_ON 1 00027 # define LED_OFF 0 00028 #else 00029 # define LED_ON 0 00030 # define LED_OFF 1 00031 #endif 00032 00033 static DigitalOut led(LED1); // LED1, being used for morse sequence 00034 static Ticker ticker; // triggers periodic callbacks 00035 static const char *pointer = 0; // 0 means morse activity disabled 00036 static const char *sequence = 0; // next morse sequence for repeats 00037 00038 void Blinker::morse(const char *pattern, double interval) 00039 { 00040 pointer = 0; // disable ticker based blinking 00041 sequence = 0; // set also empty sequence 00042 00043 for (; *pattern; pattern++) 00044 { 00045 led = (*pattern == ' ') ? LED_OFF : LED_ON; 00046 wait(interval); // busy waiting for interval time 00047 } 00048 } 00049 00050 // callback for LED1 ticker controlled blinking 00051 00052 static void cbBlinker(void) // blinker callback 00053 { 00054 if (pointer != 0) 00055 { 00056 if (*pointer == 0) 00057 { 00058 pointer = sequence; // reset pointer to followup sequence 00059 } 00060 00061 if (*pointer) 00062 { 00063 led = (*pointer++ == ' ') ? LED_OFF : LED_ON; 00064 } 00065 } 00066 } 00067 00068 void Blinker::blink(const char *pattern, const char* next, double interval) 00069 { 00070 pointer = 0; // stop current activities 00071 led = LED_OFF; // reset led with LED_OFF 00072 00073 sequence = next; // init morse sequence 00074 00075 ticker.attach(cbBlinker,interval);// next LED state after every interval 00076 pointer = pattern; // enable callback activty 00077 } 00078 00079 void Blinker::blink(const char *pattern, double interval) 00080 { 00081 blink(pattern,pattern,interval); 00082 } 00083 00084
Generated on Tue Jul 12 2022 21:31:05 by
1.7.2
