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