This is a souped up version of the basic mbed blinky, as a 2nd stepping stone up from the basic blinky and also because the documentation doesn't seem to really be that complete.
Fork of mbed_quadBlinky by
Diff: main.cpp
- Revision:
- 1:f4e48249b980
- Parent:
- 0:efe13d6feef8
diff -r efe13d6feef8 -r f4e48249b980 main.cpp --- a/main.cpp Tue Oct 03 16:53:41 2017 +0000 +++ b/main.cpp Tue Oct 03 17:00:33 2017 +0000 @@ -1,12 +1,15 @@ #include "mbed.h" +// You can write out debug strings via the mbed interface and the built-in mini-USB socket. Serial pc(USBTX, USBRX); +// All 4 built-in LEDs defined. DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); +// Example initialisation function void initialise() { // Baud rate not required over USB. @@ -27,6 +30,15 @@ wait(1.0f); } +// The LED blinking code was split out into 2 functions with different parameter +// passing methods to incrementally add more sophistication and complexity into +// the basic mbed_blinky example. Those familiar with C/C++ won't need this sort +// of help, but if mbed is your first foray into C/C++, this will help... + +// Take the parameter passed to us in variable 'val' and use the value in it +// to update the LEDs. We essentially use the value in 'val' as a bit field +// telling us which LEDs to light up, in a way that corresponds directly to the +// bit position. void updateLEDs(int val) { led1 = val & 0x01; @@ -35,6 +47,10 @@ led4 = (val & 0x08) >> 3; } +// A simple bitwise shifting function to create an LED chaser effect. +// This function is different as it takes a pointer to the original variable. +// i.e., it is expecting the address to an int variable, not simply the value +// itself. void advanceLEDs(int *val) { *val = *val << 1;