Kenji Arai / Mbed OS Arduino_Nano33BLESense_examples

Dependencies:   APDS_9960 LPS22HB LSM9DS1 HTS221

Revision:
1:cce280da16d4
Parent:
0:f1a10797d9f6
--- a/0_Blinky_LED/main0.cpp	Fri Feb 07 01:21:16 2020 +0000
+++ b/0_Blinky_LED/main0.cpp	Sun Feb 28 07:31:58 2021 +0000
@@ -1,13 +1,13 @@
 /*
  * Mbed Application program
- *  Nano 33 BLE Sense board runs on mbed-OS5
+ *  Nano 33 BLE Sense board runs on mbed-OS6
  *      3 LED (Y+G+RGB) blinky
  *
- * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * Copyright (c) 2020,'21 Kenji Arai / JH1PJL
  *      http://www7b.biglobe.ne.jp/~kenjia/
  *      https://os.mbed.com/users/kenjiArai/
  *      Started:    January   22nd, 2020
- *      Revised:    Feburary   5th, 2020
+ *      Revised:    February  28th, 2021
  */
 
 //  Pre-selection --------------------------------------------------------------
@@ -34,56 +34,105 @@
 
 //  Function prototypes --------------------------------------------------------
 
+//  subroutin (must be at this below line and do NOT change order) -------------
+#include    "usb_serial_as_stdio.h"
+#include    "check_revision.h"
+#include    "common.h"
+
 //------------------------------------------------------------------------------
 //  Control Program
 //------------------------------------------------------------------------------
 int main()
 {
-    thread_sleep_for(1000);
+    usb_serial_initialize();
+    print_revision();
+    ThisThread::sleep_for(100ms);
+    uint32_t counter = 0;
     while (true) {
+        print_usb("Blinky LED's %u\r\n", ++counter);
         led_y = 1;
         led_g = 0;
         lr = 1;
         lg = 1;
         lb = 1;
-        thread_sleep_for(1000);
+        ThisThread::sleep_for(1s);
         led_y = 0;
         led_g = 1;
         lr = 1;
         lg = 1;
         lb = 1;
-        thread_sleep_for(1000);
+        ThisThread::sleep_for(1s);
         led_y = 0;
         led_g = 0;
         lr = 0;
         lg = 1;
         lb = 1;
-        thread_sleep_for(1000);
+        ThisThread::sleep_for(1s);
         led_y = 0;
         led_g = 0;
         lr = 1;
         lg = 0;
         lb = 1;
-        thread_sleep_for(1000);
+        ThisThread::sleep_for(1s);
         led_y = 0;
         led_g = 0;
         lr = 1;
         lg = 1;
         lb = 0;
-        thread_sleep_for(1000);
+        ThisThread::sleep_for(1s);
         led_y = 1;
         led_g = 1;
         lr = 0;
         lg = 0;
         lb = 0;
-        thread_sleep_for(1000);
+        ThisThread::sleep_for(1s);
         led_y = 0;
         led_g = 0;
         lr = 1;
         lg = 1;
         lb = 1;
-        thread_sleep_for(1000);
+        ThisThread::sleep_for(1s);
+    }
+}
+
+#if 0
+/*
+    https://cpplover.blogspot.com/2010/03/variadic-templates.html
+ */
+template <typename ... Args>
+void print_usb(const char *format, Args const & ... args)
+{
+    if (usb == NULL) {
+        return;
+    } else {
+        if (usb->connected() == true) {
+            usb->printf(format, args ...);
+        }
     }
 }
 
+uint8_t readable()
+{
+    return usb->readable();
+}
+
+void putc(uint8_t c)
+{
+    if (usb == NULL) {
+        return;
+    } else {
+        usb->putc(c);
+    }
+}
+
+uint8_t getc()
+{
+    if (usb == NULL) {
+        while(true){ ;} // infinit loop
+    } else {
+        return usb->getc();
+    }
+}
+#endif
+
 #endif  // EXAMPLE_0_BLINKY_LED
\ No newline at end of file