Hello there

Dependencies:   PM2_Libary

Revision:
4:dcdcb25d1069
Parent:
3:aa1d854807fe
Child:
5:887081decd5c
--- a/main.cpp	Sat Mar 13 12:09:11 2021 +0000
+++ b/main.cpp	Sat Mar 13 13:49:08 2021 +0100
@@ -1,6 +1,8 @@
 #include "mbed.h"
 #include "platform/mbed_thread.h"
 
+#include "BufferedSerial.h"
+
 #define   pi 3.14159265358979323846 
 
 using namespace std::chrono;
@@ -8,10 +10,11 @@
 InterruptIn  user_button(USER_BUTTON);
 DigitalOut   led(LED1);
 // Serial       pc(SERIAL_TX, SERIAL_RX);
+ BufferedSerial pc(USBTX, USBRX);
 
 bool         executeMainTask = false;
 Timer        user_button_timer, loop_timer;
-int          Ts_ms = 50;
+int          Ts_ms = 1000;
 
 void         button_fall(); // stuff
 void         button_rise(); // stuff
@@ -31,8 +34,29 @@
         /* ------------- start hacking ------------- -------------*/
 
         if(executeMainTask) {
-            dist = analogIn.read()*3.3f;
-            // printf("measurement: %9.6f\r\n", dist);
+            // dist = analogIn.read()*3.3f;
+            // printf("measurement: %d\r\n", (static_cast<int>(dist * 1000)));
+
+            Timer s;
+            
+            s.start();
+            char msg[] = "Hello World - buffered\n";
+            pc.write(msg, sizeof(msg));
+            int buffered_time = duration_cast<milliseconds>(s.elapsed_time()).count();
+            thread_sleep_for(100);; // give time for the buffer to empty
+            
+            s.reset();
+            printf("Hello World - blocking\n");
+            int polled_time = duration_cast<milliseconds>(s.elapsed_time()).count();
+            s.stop();
+            thread_sleep_for(100);; // give time for the buffer to empty
+            
+            printf("printf buffered took %d us\n", buffered_time);
+            printf("printf blocking took %d us\n", polled_time);
+            thread_sleep_for(100);; // give time for the buffer to empty
+
+
+            
         } else {
 
         }