
Blinky program for SDP-K1.
Revision 10:b1071090cf50, committed 2021-02-03
- Comitter:
- Kjansen45
- Date:
- Wed Feb 03 17:27:40 2021 +0000
- Parent:
- 9:60df52b43daa
- Child:
- 11:d5709648ce80
- Commit message:
- Updating Blinky Example to Mbed OS 6
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Nov 03 15:29:33 2020 +0000 +++ b/main.cpp Wed Feb 03 17:27:40 2021 +0000 @@ -36,28 +36,40 @@ */ #include "mbed.h" -#include "platform/mbed_thread.h" - -// Blinking rate in milliseconds -#define SLEEP_TIME 500 - +// LED Blinking rate in milliseconds (Note: need to define the unit of a time duration i.e. seconds(s) or milliseconds(ms)) +#define SLEEP_TIME 500ms -// Initialise the digital pin LED4 (status LED) as an output -DigitalOut led(LED4); +// Initialise the digital pin that controls LED1 +DigitalOut led(LED1); // Initialise the serial object with TX and RX pins -Serial pc(USBTX, USBRX); +static BufferedSerial serial_port(USBTX, USBRX); - +// The File handler is needed to allow printf commands to write to the terminal +FileHandle *mbed::mbed_override_console(int fd) +{ + return &serial_port; +} // main() runs in its own thread in the OS int main() { - pc.printf("Hello World!"); - while (true) { - // Blink LED and wait 500 ms - led = !led; - thread_sleep_for(SLEEP_TIME); + // printing the Mbed OS version this example was written to the console + printf("This Application has been developed on Mbed OS version 6.4\r\n"); + + // printing the actual Mbed OS version that this application is using to the console. + printf( + "Mbed OS version %d.%d.%d is what this applicaiton is currently using\r\n", + MBED_MAJOR_VERSION, + MBED_MINOR_VERSION, + MBED_PATCH_VERSION + ); + + // The loop will toggle the LED every 500ms(SLEEP_TIME = 500ms) and print LED1s current state to the terminal + while (1) { + led = !led; // toggle LED1 state + printf("LED1 state: %d \r\n", (uint8_t)led); + ThisThread::sleep_for(SLEEP_TIME); } }