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:
- 0:639638267b89
diff -r 000000000000 -r 639638267b89 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Mar 23 03:28:18 2020 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+
+//------------------------------------
+// Hyperterminal configuration
+// 115200 bauds, 8-bit data, no parity
+//------------------------------------
+
+int m_nSec = 0;
+bool m_bChange = false;
+
+DigitalOut led1(LED1);
+Serial pc(SERIAL_TX, SERIAL_RX, 115200);
+Ticker toggle_led_ticker;
+Ticker counter_ticker;
+
+DigitalOut myled(LED1);
+
+void toggle_led()
+{
+ led1 = !led1;
+}
+
+void count_second()
+{
+ m_nSec++;
+ m_bChange = true;
+}
+
+int main()
+{
+ pc.printf("KKT : ticker + serial test\n");
+
+ // Init the ticker with the address of the function (toggle_led) to be attached and the interval (500 ms)
+ toggle_led_ticker.attach(&toggle_led, 0.5);
+ counter_ticker.attach(*count_second, 1);
+
+ while(1)
+ {
+ if (m_bChange)
+ {
+ m_bChange = false;
+ pc.printf("This program runs since %d seconds.\n", m_nSec);
+ }
+ }
+}