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.

Dependencies:   mbed

Committer:
hux
Date:
Sat Dec 10 18:34:23 2016 +0000
Revision:
1:10299215b49e
Some fine tuning; readme file added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 1:10299215b49e 1 // blink.cpp - send a morse pattern to LED1
hux 1:10299215b49e 2 //
hux 1:10299215b49e 3 // Function morse() is one way for running LED1 with a blinking sequence using
hux 1:10299215b49e 4 // a busy wait, until the sequence is completed.
hux 1:10299215b49e 5 //
hux 1:10299215b49e 6 // morse(" x xxx x "); send one time morse sequence, interval = 0.2
hux 1:10299215b49e 7 // morse(" x xxx x ",0.5); send one time morse sequence, interval = 0.5
hux 1:10299215b49e 8 //
hux 1:10299215b49e 9
hux 1:10299215b49e 10 #include "bricks/target.h"
hux 1:10299215b49e 11 #include "bricks/blink.h"
hux 1:10299215b49e 12
hux 1:10299215b49e 13 #ifndef LED_INVERTED
hux 1:10299215b49e 14 # define LED_ON 1
hux 1:10299215b49e 15 # define LED_OFF 0
hux 1:10299215b49e 16 #else
hux 1:10299215b49e 17 # define LED_ON 0
hux 1:10299215b49e 18 # define LED_OFF 1
hux 1:10299215b49e 19 #endif
hux 1:10299215b49e 20
hux 1:10299215b49e 21 static DigitalOut led(LED1); // LED1, being used for morse sequence
hux 1:10299215b49e 22
hux 1:10299215b49e 23 void morse(const char *pattern, double interval)
hux 1:10299215b49e 24 {
hux 1:10299215b49e 25 for (; *pattern; pattern++)
hux 1:10299215b49e 26 {
hux 1:10299215b49e 27 led = (*pattern == ' ') ? LED_OFF : LED_ON;
hux 1:10299215b49e 28 wait(interval); // busy waiting for interval time
hux 1:10299215b49e 29 }
hux 1:10299215b49e 30 }
hux 1:10299215b49e 31
hux 1:10299215b49e 32