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.
Diff: main.cpp
- Revision:
- 10:b1071090cf50
- Parent:
- 8:7f7b0fa6baad
diff -r 60df52b43daa -r b1071090cf50 main.cpp
--- 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);
}
}