
Tutorial 2 - SOS: This is an embedded program which controls LED1 in order to show a blinking SOS pattern. The tutorial starts to organize helper functions like "morse" in a brick library which will grow and grow with each tutorial. Platform specifics are identified in "bricks/platform.h" by setting proper defines (like LED_INVERTED), which are used to achieve platform independent behaviour. The program has been tested on Nordic nRF51-DK and STM NUCLEO-F303K8, NUCLEO-F401RE and NUCLEO-L476RG.
Diff: bricks/morse.cpp
- Revision:
- 0:9bbb539e0614
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bricks/morse.cpp Thu Dec 08 08:07:23 2016 +0000 @@ -0,0 +1,20 @@ +// morse.cpp - send a morse pattern to LED1 + +#include "bricks/platform.h" +#include "bricks/morse.h" + +#ifdef NUCLEO +# define LED_ON 0 +#else +# define LED_ON 1 +#endif + +void morse(double periode, char *pattern) +{ + DigitalOut led(LED1); + + while (*pattern) { + led = (*pattern++ == ' ') ? LED_ON : !LED_ON; + wait(periode); + } +} \ No newline at end of file