diff --git a/APIs_Drivers/AnalogIn_ex_2/main.cpp b/APIs_Drivers/AnalogIn_ex_2/main.cpp index 5084e11..cd2bdda 100644 --- a/APIs_Drivers/AnalogIn_ex_2/main.cpp +++ b/APIs_Drivers/AnalogIn_ex_2/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + AnalogIn input(A0); #define NUM_SAMPLES 1024 @@ -15,7 +17,7 @@ int main() for (int i = 0; i < NUM_SAMPLES; i++) { samples[i] = input.read_u16(); - ThisThread::sleep_for(1); + ThisThread::sleep_for(1ms); } printf("Results:\n"); diff --git a/APIs_Drivers/AnalogIn_ex_3/main.cpp b/APIs_Drivers/AnalogIn_ex_3/main.cpp index 7cdd2f3..cab4019 100644 --- a/APIs_Drivers/AnalogIn_ex_3/main.cpp +++ b/APIs_Drivers/AnalogIn_ex_3/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + // Initialize a pins to perform analog input and digital output functions AnalogIn ain(A0); DigitalOut dout(LED1); @@ -24,6 +26,6 @@ int main(void) // print the percentage and 16 bit normalized values printf("percentage: %3.3f%%\n", ain.read() * 100.0f); printf("normalized: 0x%04X \n", ain.read_u16()); - ThisThread::sleep_for(200); + ThisThread::sleep_for(200ms); } } diff --git a/APIs_Drivers/AnalogOut_ex_2/main.cpp b/APIs_Drivers/AnalogOut_ex_2/main.cpp index 836b89e..a0b151a 100644 --- a/APIs_Drivers/AnalogOut_ex_2/main.cpp +++ b/APIs_Drivers/AnalogOut_ex_2/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + // Initialize a pins to perform analog and digital output functions // Adjust analog output pin name to your board spec. AnalogOut aout(A5); @@ -20,7 +22,7 @@ int main(void) printf("aout = %1.2f volts\n", aout.read() * 3.3f); // turn on the led if the voltage is greater than 0.5f * VCC dout = (aout > 0.5f) ? 1 : 0; - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } -} \ No newline at end of file +} diff --git a/APIs_Drivers/BusInOut_ex_1/main.cpp b/APIs_Drivers/BusInOut_ex_1/main.cpp index df1c16d..3e7a6fa 100644 --- a/APIs_Drivers/BusInOut_ex_1/main.cpp +++ b/APIs_Drivers/BusInOut_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + BusInOut pins(D0, D1, D2); // Change these pins to buttons on your board. int main() @@ -12,9 +14,9 @@ int main() while (1) { pins.output(); pins = 0x3; - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); pins.input(); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); if (pins == 0x6) { printf("Hello!\n"); } diff --git a/APIs_Drivers/BusIn_ex_1/main.cpp b/APIs_Drivers/BusIn_ex_1/main.cpp index dead529..677c5f0 100644 --- a/APIs_Drivers/BusIn_ex_1/main.cpp +++ b/APIs_Drivers/BusIn_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + BusIn nibble(D0, D1, D2, D3); // Change these pins to buttons on your board. int main() @@ -48,6 +50,6 @@ int main() printf("0b1111, D3,D2,D1,D0 are high \n\r"); break; } - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_Drivers/BusOut_ex_1/main.cpp b/APIs_Drivers/BusOut_ex_1/main.cpp index a54e956..a27c292 100644 --- a/APIs_Drivers/BusOut_ex_1/main.cpp +++ b/APIs_Drivers/BusOut_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + BusOut myleds(LED1, LED2, LED3, LED4); int main() @@ -12,7 +14,7 @@ int main() while (1) { for (int i = 0; i < 16; i++) { myleds = i; - ThisThread::sleep_for(250); + ThisThread::sleep_for(250ms); } } } diff --git a/APIs_Drivers/CAN_ex_1/main.cpp b/APIs_Drivers/CAN_ex_1/main.cpp index 51ea3ef..a4995c9 100644 --- a/APIs_Drivers/CAN_ex_1/main.cpp +++ b/APIs_Drivers/CAN_ex_1/main.cpp @@ -10,6 +10,7 @@ #include "mbed.h" +using namespace std::chrono_literals; Ticker ticker; DigitalOut led1(LED1); @@ -43,7 +44,7 @@ int main() printf("Message received: %d\n", msg.data[0]); led2 = !led2; } - ThisThread::sleep_for(200); + ThisThread::sleep_for(200ms); } } diff --git a/APIs_Drivers/DigitalInOut_ex_1/main.cpp b/APIs_Drivers/DigitalInOut_ex_1/main.cpp index 24d85e2..45a656f 100644 --- a/APIs_Drivers/DigitalInOut_ex_1/main.cpp +++ b/APIs_Drivers/DigitalInOut_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + DigitalInOut mypin(LED1); int main() @@ -21,11 +23,11 @@ int main() // write to pin as output mypin.output(); mypin = !mypin; // toggle output - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); // read from pin as input mypin.input(); printf("mypin.read() = %d \n\r", mypin.read()); - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); } } diff --git a/APIs_Drivers/DigitalIn_ex_1/main.cpp b/APIs_Drivers/DigitalIn_ex_1/main.cpp index e03d6aa..80db9c1 100644 --- a/APIs_Drivers/DigitalIn_ex_1/main.cpp +++ b/APIs_Drivers/DigitalIn_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + DigitalIn mypin(SW2); // change this to the button on your board DigitalOut myled(LED1); @@ -22,6 +24,6 @@ int main() while (1) { printf("mypin has value : %d \n\r", mypin.read()); myled = mypin; // toggle led based on value of button - ThisThread::sleep_for(250); + ThisThread::sleep_for(250ms); } } diff --git a/APIs_Drivers/DigitalOut_ex_1/main.cpp b/APIs_Drivers/DigitalOut_ex_1/main.cpp index 6ddc38d..e0dd20c 100644 --- a/APIs_Drivers/DigitalOut_ex_1/main.cpp +++ b/APIs_Drivers/DigitalOut_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + DigitalOut myled(LED1); int main() @@ -18,10 +20,10 @@ int main() while (1) { myled = 1; // set LED1 pin to high printf("myled = %d \n\r", (uint8_t)myled); - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); myled.write(0); // set LED1 pin to low printf("myled = %d \n\r", myled.read()); - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); } } diff --git a/APIs_Drivers/I2C_ex_1/main.cpp b/APIs_Drivers/I2C_ex_1/main.cpp index f5c2cb5..8729489 100644 --- a/APIs_Drivers/I2C_ex_1/main.cpp +++ b/APIs_Drivers/I2C_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + // Read temperature from LM75BD I2C i2c(I2C_SDA, I2C_SCL); @@ -20,7 +22,7 @@ int main() cmd[1] = 0x00; i2c.write(addr8bit, cmd, 2); - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); cmd[0] = 0x00; i2c.write(addr8bit, cmd, 1); diff --git a/APIs_Drivers/InterruptIn_ex_1/main.cpp b/APIs_Drivers/InterruptIn_ex_1/main.cpp index 1797ea7..50893a0 100644 --- a/APIs_Drivers/InterruptIn_ex_1/main.cpp +++ b/APIs_Drivers/InterruptIn_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + class Counter { public: Counter(PinName pin) : _interrupt(pin) // create the InterruptIn on the pin specified to Counter @@ -33,6 +35,6 @@ int main() { while (1) { printf("Count so far: %d\n", counter.read()); - ThisThread::sleep_for(2000); + ThisThread::sleep_for(2s); } } diff --git a/APIs_Drivers/InterruptIn_ex_2/main.cpp b/APIs_Drivers/InterruptIn_ex_2/main.cpp index 1b90ce2..619e6de 100644 --- a/APIs_Drivers/InterruptIn_ex_2/main.cpp +++ b/APIs_Drivers/InterruptIn_ex_2/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + InterruptIn button(SW2); DigitalOut led(LED1); DigitalOut flash(LED4); @@ -19,6 +21,6 @@ int main() button.rise(&flip); // attach the address of the flip function to the rising edge while (1) { // wait around, interrupts will interrupt this! flash = !flash; - ThisThread::sleep_for(250); + ThisThread::sleep_for(250ms); } } diff --git a/APIs_Drivers/PortIn_ex_1/main.cpp b/APIs_Drivers/PortIn_ex_1/main.cpp index 46d9a2c..f302fb3 100644 --- a/APIs_Drivers/PortIn_ex_1/main.cpp +++ b/APIs_Drivers/PortIn_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + // Toggle all four LEDs // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 #define LED_MASK 0x00B40000 @@ -17,8 +19,8 @@ int main() ledport.output(); while (1) { ledport = LED_MASK; - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); ledport = 0; - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_Drivers/PortOut_ex_1/main.cpp b/APIs_Drivers/PortOut_ex_1/main.cpp index 8a02e23..c2cefd6 100644 --- a/APIs_Drivers/PortOut_ex_1/main.cpp +++ b/APIs_Drivers/PortOut_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + // Toggle all four LEDs // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 #define LED_MASK 0x00B40000 @@ -15,8 +17,8 @@ int main() { while (1) { ledport = LED_MASK; - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); ledport = 0; - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_Drivers/QSPI/main.cpp b/APIs_Drivers/QSPI/main.cpp index ca322d8..4258813 100644 --- a/APIs_Drivers/QSPI/main.cpp +++ b/APIs_Drivers/QSPI/main.cpp @@ -21,6 +21,8 @@ #include "mbed.h" #include "drivers/QSPI.h" +using namespace std::chrono_literals; + // For Nordic platforms, use fast read. The QSPI flash memory start address, // along with the total buffer size, needs to be 4-byte aligned, or divisible by 4. #if TARGET_NORDIC @@ -53,7 +55,7 @@ static bool mem_ready() if (QSPI_STATUS_OK != qspi_device.command_transfer(CMD_RDSR, -1, NULL, 0, status_value, STATUS_REG_SIZE)) { printf("Reading Status Register failed \n"); } - ThisThread::sleep_for(1); + ThisThread::sleep_for(1ms); } while ((status_value[0] & BIT_WIP) != 0 && retries); if ((status_value[0] & BIT_WIP) != 0) { diff --git a/APIs_Drivers/Ticker_Example/main.cpp b/APIs_Drivers/Ticker_Example/main.cpp index 4a49314..57387c6 100644 --- a/APIs_Drivers/Ticker_Example/main.cpp +++ b/APIs_Drivers/Ticker_Example/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + // A class for flip()-ing a DigitalOut class Flipper { public: @@ -26,11 +28,11 @@ Ticker t; int main() { // the address of the object, member function, and interval - t.attach(callback(&f, &Flipper::flip), 2.0); + t.attach(callback(&f, &Flipper::flip), 2s); // spin in a main loop. flipper will interrupt it to call flip while (1) { led1 = !led1; - ThisThread::sleep_for(200); + ThisThread::sleep_for(200ms); } } diff --git a/APIs_Drivers/Ticker_HelloWorld/main.cpp b/APIs_Drivers/Ticker_HelloWorld/main.cpp index 8e94c37..7a9e5ae 100644 --- a/APIs_Drivers/Ticker_HelloWorld/main.cpp +++ b/APIs_Drivers/Ticker_HelloWorld/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + Ticker flipper; DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -16,11 +18,11 @@ void flip() int main() { led2 = 1; - flipper.attach(&flip, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds) + flipper.attach(&flip, 2s); // the address of the function to be attached (flip) and the interval (2 seconds) // spin in a main loop. flipper will interrupt it to call flip while (1) { led1 = !led1; - ThisThread::sleep_for(200); + ThisThread::sleep_for(200ms); } } diff --git a/APIs_Drivers/Timeout_Example/main.cpp b/APIs_Drivers/Timeout_Example/main.cpp index 8a887b2..5fd0a92 100644 --- a/APIs_Drivers/Timeout_Example/main.cpp +++ b/APIs_Drivers/Timeout_Example/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + // A class for flip()-ing a DigitalOut class Flipper { public: @@ -26,11 +28,11 @@ Timeout t; int main() { // the address of the object, member function, and interval - t.attach(callback(&f, &Flipper::flip), 2.0); + t.attach(callback(&f, &Flipper::flip), 2s); // spin in a main loop. flipper will interrupt it to call flip while (1) { led1 = !led1; - ThisThread::sleep_for(200); + ThisThread::sleep_for(200ms); } } diff --git a/APIs_Drivers/Timeout_HelloWorld/main.cpp b/APIs_Drivers/Timeout_HelloWorld/main.cpp index cf36eb3..ef00078 100644 --- a/APIs_Drivers/Timeout_HelloWorld/main.cpp +++ b/APIs_Drivers/Timeout_HelloWorld/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + Timeout flipper; DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -16,11 +18,11 @@ void flip() int main() { led2 = 1; - flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds + flipper.attach(&flip, 2s); // setup flipper to call flip after 2 seconds // spin in a main loop. flipper will interrupt it to call flip while (1) { led1 = !led1; - ThisThread::sleep_for(200); + ThisThread::sleep_for(200ms); } } diff --git a/APIs_Drivers/Watchdog_ex_1/main.cpp b/APIs_Drivers/Watchdog_ex_1/main.cpp index 2d7e41f..21cfe60 100644 --- a/APIs_Drivers/Watchdog_ex_1/main.cpp +++ b/APIs_Drivers/Watchdog_ex_1/main.cpp @@ -5,9 +5,13 @@ #include "mbed.h" -const uint32_t TIMEOUT_MS = 5000; +#include + +using namespace std::chrono_literals; + +const auto TIMEOUT = 5000ms; InterruptIn button(BUTTON1); -volatile int countdown = 9; +volatile int countdown{9}; void trigger() { @@ -20,7 +24,7 @@ int main() printf("\r\nTarget started.\r\n"); Watchdog &watchdog = Watchdog::get_instance(); - watchdog.start(TIMEOUT_MS); + watchdog.start(TIMEOUT.count()); button.rise(&trigger); uint32_t watchdog_timeout = watchdog.get_timeout(); @@ -31,6 +35,6 @@ int main() while (1) { printf("\r%3i", countdown--); fflush(stdout); - ThisThread::sleep_for(TIMEOUT_MS / 10); + ThisThread::sleep_for(TIMEOUT / 10); } } diff --git a/APIs_Drivers/lowpowerTicker_ex_1/main.cpp b/APIs_Drivers/lowpowerTicker_ex_1/main.cpp index 910dfa1..a54904d 100644 --- a/APIs_Drivers/lowpowerTicker_ex_1/main.cpp +++ b/APIs_Drivers/lowpowerTicker_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + LowPowerTicker flipper; DigitalOut led1(LED1); @@ -16,9 +18,9 @@ void flip() int main() { led1 = 1; - flipper.attach(&flip, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds) + flipper.attach(&flip, 2s); // the address of the function to be attached (flip) and the interval (2 seconds) while (1) { - ThisThread::sleep_for(200); + ThisThread::sleep_for(200ms); } } diff --git a/APIs_Drivers/lowpowerTimeout_ex_1/main.cpp b/APIs_Drivers/lowpowerTimeout_ex_1/main.cpp index 499153d..f5acfa6 100644 --- a/APIs_Drivers/lowpowerTimeout_ex_1/main.cpp +++ b/APIs_Drivers/lowpowerTimeout_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + LowPowerTimeout flipper; DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -17,11 +19,11 @@ void flip() int main() { led2 = 1; - flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds + flipper.attach(&flip, 2s); // setup flipper to call flip after 2 seconds // spin in a main loop. flipper will interrupt it to call flip while (1) { led1 = !led1; - ThisThread::sleep_for(200); + ThisThread::sleep_for(200ms); } } diff --git a/APIs_NetworkSocket/TCPSocket_ConnStateCb/main.cpp b/APIs_NetworkSocket/TCPSocket_ConnStateCb/main.cpp index d34efaf..12e5262 100644 --- a/APIs_NetworkSocket/TCPSocket_ConnStateCb/main.cpp +++ b/APIs_NetworkSocket/TCPSocket_ConnStateCb/main.cpp @@ -6,6 +6,8 @@ #include "mbed.h" #include "nsapi_types.h" +using namespace std::chrono_literals; + // Network interface EthernetInterface eth; Mutex print_mutex; @@ -50,7 +52,7 @@ int main() eth.connect(); safe_print("Connecting started...\r\n"); - ThisThread::sleep_for(10000); + ThisThread::sleep_for(10s); safe_print("Disconnect\r\n"); eth.disconnect(); diff --git a/APIs_Platform/DeepSleepLock_Example_1/main.cpp b/APIs_Platform/DeepSleepLock_Example_1/main.cpp index 2cb86b0..a481bcd 100644 --- a/APIs_Platform/DeepSleepLock_Example_1/main.cpp +++ b/APIs_Platform/DeepSleepLock_Example_1/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + InterruptIn button(BUTTON1); DigitalOut led(LED1); @@ -23,6 +25,6 @@ int main() while (1) { // Wait and let interrupts take care of the rest - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_Platform/FileHandle_sigio/main.cpp b/APIs_Platform/FileHandle_sigio/main.cpp index 8ee022a..fd882fa 100644 --- a/APIs_Platform/FileHandle_sigio/main.cpp +++ b/APIs_Platform/FileHandle_sigio/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + static DigitalOut led1(LED1); static DigitalOut led2(LED2); @@ -35,6 +37,6 @@ int main() while (1) { led1 = !led1; - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); } } diff --git a/APIs_Platform/Memory_tracing_ex_1/main.cpp b/APIs_Platform/Memory_tracing_ex_1/main.cpp index dbcfaf7..b515cc2 100644 --- a/APIs_Platform/Memory_tracing_ex_1/main.cpp +++ b/APIs_Platform/Memory_tracing_ex_1/main.cpp @@ -7,6 +7,7 @@ #include "mbed.h" #include "mbed_mem_trace.h" +using namespace std::chrono_literals; int main() { @@ -15,7 +16,7 @@ int main() void *p = malloc(50); printf("50B allocated at %p\n", p); - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); free(p); printf("50B freed at %p\n\n", p); diff --git a/APIs_Platform/PlatformMutex_ex_1/main.cpp b/APIs_Platform/PlatformMutex_ex_1/main.cpp index 606d300..38dca2c 100644 --- a/APIs_Platform/PlatformMutex_ex_1/main.cpp +++ b/APIs_Platform/PlatformMutex_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + PlatformMutex stdio_mutex; Thread t2; Thread t3; @@ -16,20 +18,20 @@ void notify(const char *name, int state) stdio_mutex.unlock(); } -void test_thread(void const *args) +void test_thread(const char *args) { while (true) { - notify((const char *)args, 0); - ThisThread::sleep_for(1000); - notify((const char *)args, 1); - ThisThread::sleep_for(1000); + notify(args, 0); + ThisThread::sleep_for(1s); + notify(args, 1); + ThisThread::sleep_for(1s); } } int main() { - t2.start(callback(test_thread, (void *)"Th 2")); - t3.start(callback(test_thread, (void *)"Th 3")); + t2.start(callback(test_thread, "Th 2")); + t3.start(callback(test_thread, "Th 3")); - test_thread((void *)"Th 1"); + test_thread("Th 1"); } diff --git a/APIs_Platform/PlatfromOverview_Callbacks/main.cpp b/APIs_Platform/PlatfromOverview_Callbacks/main.cpp index 6758d58..53b6f37 100644 --- a/APIs_Platform/PlatfromOverview_Callbacks/main.cpp +++ b/APIs_Platform/PlatfromOverview_Callbacks/main.cpp @@ -7,14 +7,14 @@ // Create a serial object static UnbufferedSerial serial(USBTX, USBRX); -char *c = new char[1]; // A function that echoes any received data back void echo() { while (serial.readable()) { - serial.read(c, sizeof(c)); - serial.write(c, sizeof(c)); + char c; + serial.read(&c, sizeof(c)); + serial.write(&c, sizeof(c)); } } diff --git a/APIs_Platform/SleepManager_Example_1/main.cpp b/APIs_Platform/SleepManager_Example_1/main.cpp index 95570ae..0e595a2 100644 --- a/APIs_Platform/SleepManager_Example_1/main.cpp +++ b/APIs_Platform/SleepManager_Example_1/main.cpp @@ -4,12 +4,13 @@ */ #include "mbed.h" +using namespace std::chrono_literals; int main() { // Deep sleep for 1 second printf("Deep sleep allowed: %i\r\n", sleep_manager_can_deep_sleep()); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); // Lock deep sleep printf("Locking deep sleep\r\n"); @@ -17,5 +18,5 @@ int main() // Sleep for 1 second printf("Deep sleep allowed: %i\r\n", sleep_manager_can_deep_sleep()); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } diff --git a/APIs_Platform/time_HelloWorld/main.cpp b/APIs_Platform/time_HelloWorld/main.cpp index c68b87d..90032f1 100644 --- a/APIs_Platform/time_HelloWorld/main.cpp +++ b/APIs_Platform/time_HelloWorld/main.cpp @@ -4,6 +4,7 @@ */ #include "mbed.h" +using namespace std::chrono_literals; int main() { @@ -20,6 +21,6 @@ int main() strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); printf("Time as a custom formatted string = %s", buffer); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_RTOS/Basic/main.cpp b/APIs_RTOS/Basic/main.cpp index 7359a21..2f40b43 100644 --- a/APIs_RTOS/Basic/main.cpp +++ b/APIs_RTOS/Basic/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + DigitalOut led1(LED1); DigitalOut led2(LED2); Thread thread; @@ -12,7 +14,7 @@ void led2_thread() { while (true) { led2 = !led2; - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } @@ -22,6 +24,6 @@ int main() while (true) { led1 = !led1; - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); } } diff --git a/APIs_RTOS/ConditionVariable_ex_1/main.cpp b/APIs_RTOS/ConditionVariable_ex_1/main.cpp index d1799af..df807df 100644 --- a/APIs_RTOS/ConditionVariable_ex_1/main.cpp +++ b/APIs_RTOS/ConditionVariable_ex_1/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + Mutex mutex; ConditionVariable cond(mutex); @@ -40,7 +42,7 @@ int main() cond.notify_all(); mutex.unlock(); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } mutex.lock(); diff --git a/APIs_RTOS/EventFlags/main.cpp b/APIs_RTOS/EventFlags/main.cpp index 9dfa357..bf0bc72 100644 --- a/APIs_RTOS/EventFlags/main.cpp +++ b/APIs_RTOS/EventFlags/main.cpp @@ -1,5 +1,7 @@ #include "mbed.h" +using namespace std::chrono_literals; + #define SAMPLE_FLAG1 (1UL << 0) #define SAMPLE_FLAG2 (1UL << 9) @@ -21,9 +23,9 @@ int main() worker_thread.start(mbed::callback(worker_thread_fun)); while (true) { - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); event_flags.set(SAMPLE_FLAG1); - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); event_flags.set(SAMPLE_FLAG2); } } diff --git a/APIs_RTOS/Events_ex_1/main.cpp b/APIs_RTOS/Events_ex_1/main.cpp index 92dba9a..4070177 100644 --- a/APIs_RTOS/Events_ex_1/main.cpp +++ b/APIs_RTOS/Events_ex_1/main.cpp @@ -10,7 +10,6 @@ void handler(int count); Event event1(&queue, handler); Event event2(&queue, handler); - void handler(int count) { unsigned time_ms = equeue_tick(); @@ -25,20 +24,18 @@ void post_events(void) // subject to any delay and period specified. Each time an event has // been dispatched it will be re-queued ready for the next dispatch // period. - event1.post(1); // Event1 with a value of 1 - event1.post(2); // Event1 with a value of 2 - event1.post(3); // Event1 with a value of 3 + event1.post(1); // Event1 with a value of 1 + event1.post(2); // Event1 with a value of 2 + event1.post(3); // Event1 with a value of 3 // Cancel the last event posted ie Event1 with a value of 3 event1.cancel(); - event1.post(4); // Event1 with a value of 4 - - event2.post(5); // Event2 with a value of 5 + event1.post(4); // Event1 with a value of 4 + event2.post(5); // Event2 with a value of 5 } - // Example demonstrates the following: // 1. Post 5 different events to a queue // 2. Configure the event delay and period for each @@ -83,11 +80,11 @@ int main() // The event can be manually configured for special timing requirements // specified in milliseconds (using Chrono durations) - event1.delay(100ms); // Starting delay - 100 msec - event1.period(200ms); // Delay between each event - 200msec + event1.delay(100ms); // Starting delay - 100 msec + event1.period(200ms); // Delay between each event - 200msec - event2.delay(400ms); // Starting delay - 400 msec - event2.period(non_periodic); // Single non periodic event + event2.delay(400ms); // Starting delay - 400 msec + event2.period(non_periodic); // Single non periodic event event_thread.start(callback(post_events)); @@ -99,5 +96,4 @@ int main() queue.dispatch_for(800ms); event_thread.join(); - } diff --git a/APIs_RTOS/Flags/main.cpp b/APIs_RTOS/Flags/main.cpp index 90ef977..dfc6e41 100644 --- a/APIs_RTOS/Flags/main.cpp +++ b/APIs_RTOS/Flags/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + Thread thread; DigitalOut led(LED1); @@ -21,7 +23,7 @@ int main(void) thread.start(callback(led_thread)); while (true) { - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); thread.flags_set(0x1); } } diff --git a/APIs_RTOS/Isr/main.cpp b/APIs_RTOS/Isr/main.cpp index becba95..129d6e2 100644 --- a/APIs_RTOS/Isr/main.cpp +++ b/APIs_RTOS/Isr/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + Ticker ticker; Thread thread; Queue trail; @@ -36,7 +38,7 @@ void handler() print_lock.unlock(); while (true) { trail.put(&(ExecutionMessages[USER])); - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); } } } diff --git a/APIs_RTOS/Kernel_get_ms_count/main.cpp b/APIs_RTOS/Kernel_get_ms_count/main.cpp index be851a3..f63185f 100644 --- a/APIs_RTOS/Kernel_get_ms_count/main.cpp +++ b/APIs_RTOS/Kernel_get_ms_count/main.cpp @@ -4,18 +4,20 @@ */ #include "mbed.h" +using namespace std::chrono; + int main() { // 64-bit time doesn't wrap for half a billion years, at least - uint64_t now = Kernel::get_ms_count(); + Kernel::Clock::time_point now = Kernel::Clock::now(); // wait a while - ThisThread::sleep_for(10); + ThisThread::sleep_for(10ms); - uint64_t later = Kernel::get_ms_count(); + Kernel::Clock::time_point later = Kernel::Clock::now(); //calculate millisecs elapsed - uint64_t elapsed_ms = later - now; + milliseconds elapsed_ms = later - now; - printf("Elapsed ms: %u \r\n", (uint32_t)elapsed_ms); + printf("Elapsed ms: %u \r\n", (uint32_t)elapsed_ms.count()); } diff --git a/APIs_RTOS/Kernel_hooks/main.cpp b/APIs_RTOS/Kernel_hooks/main.cpp index 939ab77..6f78d7e 100644 --- a/APIs_RTOS/Kernel_hooks/main.cpp +++ b/APIs_RTOS/Kernel_hooks/main.cpp @@ -5,11 +5,13 @@ #include "mbed.h" #include "Kernel.h" +using namespace std::chrono_literals; + /* Entry function for test thread */ void test_thread(void) { printf("\ntest thread started"); - ThisThread::sleep_for(2000); + ThisThread::sleep_for(2s); printf("\ntest thread exiting"); } @@ -37,14 +39,14 @@ int main() Kernel::attach_thread_terminate_hook(thread_terminate_hook); Thread *newThread = new Thread(osPriorityNormal1, 1024, NULL, NULL); newThread->start(callback(test_thread)); - ThisThread::sleep_for(4000); + ThisThread::sleep_for(4s); printf("\n\nattach_idle_hook demo:\n"); //Attach a hook for idle task Kernel::attach_idle_hook(test_idle_hook); while (1) { - ThisThread::sleep_for(3000); + ThisThread::sleep_for(3s); } printf("\n\n"); } diff --git a/APIs_RTOS/Mail/main.cpp b/APIs_RTOS/Mail/main.cpp index 85e6806..d5b6fd4 100644 --- a/APIs_RTOS/Mail/main.cpp +++ b/APIs_RTOS/Mail/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + /* Mail */ typedef struct { float voltage; /* AD result of measured voltage */ @@ -24,7 +26,7 @@ void send_thread(void) mail->current = (i * 0.1) * 11; mail->counter = i; mail_box.put(mail); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_RTOS/Mutex/main.cpp b/APIs_RTOS/Mutex/main.cpp index 360fa6f..299871e 100644 --- a/APIs_RTOS/Mutex/main.cpp +++ b/APIs_RTOS/Mutex/main.cpp @@ -15,20 +15,20 @@ void notify(const char *name, int state) stdio_mutex.unlock(); } -void test_thread(void const *args) +void test_thread(const char *args) { while (true) { - notify((const char *)args, 0); - ThisThread::sleep_for(1000); - notify((const char *)args, 1); - ThisThread::sleep_for(1000); + notify(args, 0); + ThisThread::sleep_for(1s); + notify(args, 1); + ThisThread::sleep_for(1s); } } int main() { - t2.start(callback(test_thread, (void *)"Th 2")); - t3.start(callback(test_thread, (void *)"Th 3")); + t2.start(callback(test_thread, "Th 2")); + t3.start(callback(test_thread, "Th 3")); - test_thread((void *)"Th 1"); + test_thread("Th 1"); } diff --git a/APIs_RTOS/Queue/main.cpp b/APIs_RTOS/Queue/main.cpp index 2854275..9aa751f 100644 --- a/APIs_RTOS/Queue/main.cpp +++ b/APIs_RTOS/Queue/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + typedef struct { float voltage; /* AD result of measured voltage */ float current; /* AD result of measured current */ @@ -25,7 +27,7 @@ void send_thread(void) message->current = (i * 0.1) * 11; message->counter = i; queue.put(message); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_RTOS/Semaphore/main.cpp b/APIs_RTOS/Semaphore/main.cpp index 61c633e..f8ff611 100644 --- a/APIs_RTOS/Semaphore/main.cpp +++ b/APIs_RTOS/Semaphore/main.cpp @@ -4,24 +4,26 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + Semaphore one_slot(1); Thread t2; Thread t3; -void test_thread(void const *name) +void test_thread(const char *name) { while (true) { one_slot.acquire(); - printf("%s\n\r", (const char *)name); - ThisThread::sleep_for(1000); + printf("%s\n\r", name); + ThisThread::sleep_for(1s); one_slot.release(); } } int main(void) { - t2.start(callback(test_thread, (void *)"Th 2")); - t3.start(callback(test_thread, (void *)"Th 3")); + t2.start(callback(test_thread, "Th 2")); + t3.start(callback(test_thread, "Th 3")); - test_thread((void *)"Th 1"); + test_thread("Th 1"); } diff --git a/APIs_RTOS/Sonar/main.cpp b/APIs_RTOS/Sonar/main.cpp index 4e50841..cefcc4b 100644 --- a/APIs_RTOS/Sonar/main.cpp +++ b/APIs_RTOS/Sonar/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono; + /** * Sonar class for the HC-SR04 */ @@ -13,9 +15,7 @@ class Sonar { Timer timer; Timeout timeout; // calls a callback once when a timeout expires Ticker ticker; // calls a callback repeatedly with a timeout - int32_t begin; - int32_t end; - float distance; + duration echo_time; public: /** @@ -27,7 +27,7 @@ class Sonar { Sonar(PinName trigger_pin, PinName echo_pin) : trigger(trigger_pin), echo(echo_pin) { trigger = 0; - distance = -1; + echo_time = -1us; echo.rise(callback(this, &Sonar::echo_in)); // Attach handler to the rising interruptIn edge echo.fall(callback(this, &Sonar::echo_fall)); // Attach handler to the falling interruptIn edge @@ -38,7 +38,7 @@ class Sonar { */ void start(void) { - ticker.attach(callback(this, &Sonar::background_read), 0.01f); + ticker.attach(callback(this, &Sonar::background_read), 100ms); } /** @@ -56,7 +56,6 @@ class Sonar { { timer.reset(); timer.start(); - begin = timer.read_us(); } /** @@ -65,9 +64,8 @@ class Sonar { */ void echo_fall(void) { - end = timer.read_us(); + echo_time = timer.elapsed_time(); timer.stop(); - distance = end - begin; } /** @@ -85,7 +83,7 @@ class Sonar { void background_read(void) { trigger = 1; - timeout.attach(callback(this, &Sonar::trigger_toggle), 10.0e-6); + timeout.attach(callback(this, &Sonar::trigger_toggle), 1us); } /** @@ -93,7 +91,8 @@ class Sonar { */ float read(void) { - return distance / 58.0f; + const chrono::duration us_per_cm{58.0f}; + return echo_time / us_per_cm; } }; @@ -106,7 +105,7 @@ int main() sonar.start(); while (1) { - ThisThread::sleep_for(100); + ThisThread::sleep_for(100ms); // Periodically print results from sonar object printf("%f\r\n", sonar.read()); } diff --git a/APIs_RTOS/Threading_with_callback/main.cpp b/APIs_RTOS/Threading_with_callback/main.cpp index 222b553..e24d97d 100644 --- a/APIs_RTOS/Threading_with_callback/main.cpp +++ b/APIs_RTOS/Threading_with_callback/main.cpp @@ -4,6 +4,8 @@ */ #include "mbed.h" +using namespace std::chrono_literals; + Thread thread; DigitalOut led1(LED1); volatile bool running = true; @@ -13,7 +15,7 @@ void blink(DigitalOut *led) { while (running) { *led = !*led; - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } @@ -21,7 +23,7 @@ void blink(DigitalOut *led) int main() { thread.start(callback(blink, &led1)); - ThisThread::sleep_for(5000); + ThisThread::sleep_for(5s); running = false; thread.join(); } diff --git a/APIs_USB/USBCDC/main.cpp b/APIs_USB/USBCDC/main.cpp index c633dc6..d4f7f1c 100644 --- a/APIs_USB/USBCDC/main.cpp +++ b/APIs_USB/USBCDC/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" #include "USBCDC.h" +using namespace std::chrono_literals; + USBCDC cdc; int main(void) @@ -13,6 +15,6 @@ int main(void) while (1) { char msg[] = "Hello world\r\n"; cdc.send((uint8_t *)msg, strlen(msg)); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_USB/USBCDC_ECM/main.cpp b/APIs_USB/USBCDC_ECM/main.cpp index c78bdcf..d34c75b 100644 --- a/APIs_USB/USBCDC_ECM/main.cpp +++ b/APIs_USB/USBCDC_ECM/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" #include "USBCDC_ECM.h" +using namespace std::chrono_literals; + /* Ethernet II frame */ typedef struct { uint8_t dst_mac[6]; @@ -25,11 +27,11 @@ USBCDC_ECM ecm; int main() { // Let the USB device to setup - ThisThread::sleep_for(10); + ThisThread::sleep_for(10ms); // Send "Hello world" packets in loop while (true) { ecm.send((uint8_t *)&packet, sizeof(packet)); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_USB/USBKeyboard/main.cpp b/APIs_USB/USBKeyboard/main.cpp index 00e0faa..445eac5 100644 --- a/APIs_USB/USBKeyboard/main.cpp +++ b/APIs_USB/USBKeyboard/main.cpp @@ -7,10 +7,12 @@ USBKeyboard key; +using namespace std::chrono_literals; + int main(void) { while (1) { key.printf("Hello World\r\n"); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/APIs_USB/USBMIDI/main.cpp b/APIs_USB/USBMIDI/main.cpp index ded120f..c7cd51f 100644 --- a/APIs_USB/USBMIDI/main.cpp +++ b/APIs_USB/USBMIDI/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" #include "USBMIDI.h" +using namespace std::chrono_literals; + USBMIDI midi; int main() @@ -12,9 +14,9 @@ int main() while (1) { for (int i = 48; i < 83; i++) { // send some messages! midi.write(MIDIMessage::NoteOn(i)); - ThisThread::sleep_for(250); + ThisThread::sleep_for(250ms); midi.write(MIDIMessage::NoteOff(i)); - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); } } -} \ No newline at end of file +} diff --git a/APIs_USB/USBMIDI_Take_Me_Out/main.cpp b/APIs_USB/USBMIDI_Take_Me_Out/main.cpp index 5d797f4..dfea876 100644 --- a/APIs_USB/USBMIDI_Take_Me_Out/main.cpp +++ b/APIs_USB/USBMIDI_Take_Me_Out/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" #include "USBMIDI.h" +using namespace std::chrono_literals; + #define REST -1 #define C 0 #define Cs 1 @@ -28,7 +30,7 @@ #define OCTAVE6 72 #define OCTAVE7 84 -#define WHOLE_NOTE 1150 +#define WHOLE_NOTE 1150ms #define HALF_NOTE (WHOLE_NOTE / 2) #define QUARTER_NOTE (WHOLE_NOTE / 4) #define EIGHTH_NOTE (WHOLE_NOTE / 8) @@ -39,7 +41,7 @@ USBMIDI midi; -void PlayNote(int note, int octave, uint32_t duration) +void PlayNote(int note, int octave, chrono::milliseconds duration) { if (note == REST) { ThisThread::sleep_for(duration); diff --git a/APIs_USB/USBMouseKeyboard/main.cpp b/APIs_USB/USBMouseKeyboard/main.cpp index 2b91d8b..4e18546 100644 --- a/APIs_USB/USBMouseKeyboard/main.cpp +++ b/APIs_USB/USBMouseKeyboard/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" #include "USBMouseKeyboard.h" +using namespace std::chrono_literals; + //LED1: NUM_LOCK //LED2: CAPS_LOCK //LED3: SCROLL_LOCK @@ -32,14 +34,14 @@ int main(void) //example of modifier key press key_mouse.key_code(KEY_CAPS_LOCK); leds = key_mouse.lock_status(); - ThisThread::sleep_for(50); + ThisThread::sleep_for(50ms); key_mouse.media_control(KEY_VOLUME_UP); key_mouse.key_code(KEY_NUM_LOCK); leds = key_mouse.lock_status(); - ThisThread::sleep_for(50); + ThisThread::sleep_for(50ms); angle += 10; key_mouse.key_code(KEY_SCROLL_LOCK); leds = key_mouse.lock_status(); - ThisThread::sleep_for(50); + ThisThread::sleep_for(50ms); } } diff --git a/APIs_USB/USBMouse_absolute_pos/main.cpp b/APIs_USB/USBMouse_absolute_pos/main.cpp index 2764fbb..9c70e2c 100644 --- a/APIs_USB/USBMouse_absolute_pos/main.cpp +++ b/APIs_USB/USBMouse_absolute_pos/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" #include "USBMouse.h" +using namespace std::chrono_literals; + //setup mouse to be absolute USBMouse mouse(true, ABS_MOUSE); @@ -29,6 +31,6 @@ int main(void) //x_screen, y_screen will be the mouse's position on the screen mouse.move(x_screen, y_screen); angle += 3; - ThisThread::sleep_for(10); + ThisThread::sleep_for(10ms); } -} \ No newline at end of file +} diff --git a/APIs_USB/USBMouse_joystick/main.cpp b/APIs_USB/USBMouse_joystick/main.cpp index 75fa762..d178af4 100644 --- a/APIs_USB/USBMouse_joystick/main.cpp +++ b/APIs_USB/USBMouse_joystick/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" #include "USBMouse.h" +using namespace std::chrono_literals; + USBMouse mouse; // x and y axis of the joystick AnalogIn ainx(A0); @@ -55,10 +57,10 @@ int main() if (a_iny == 99) { //click mouse.click(MOUSE_LEFT); - ThisThread::sleep_for(400); + ThisThread::sleep_for(400ms); } // moves mouse to specified x, y coordinates on screen mouse.move(x, y); - ThisThread::sleep_for(1); + ThisThread::sleep_for(1ms); } } diff --git a/APIs_USB/USBMouse_relative_pos/main.cpp b/APIs_USB/USBMouse_relative_pos/main.cpp index 26663c1..dac1db4 100644 --- a/APIs_USB/USBMouse_relative_pos/main.cpp +++ b/APIs_USB/USBMouse_relative_pos/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" #include "USBMouse.h" +using namespace std::chrono_literals; + //create mouse object USBMouse mouse; @@ -23,6 +25,6 @@ int main() //will move mouse x, y away from its previous position on the screen mouse.move(x, y); angle += 3; - ThisThread::sleep_for(10); + ThisThread::sleep_for(10ms); } } diff --git a/APIs_USB/USBSerial/main.cpp b/APIs_USB/USBSerial/main.cpp index 00759b5..5aefffb 100644 --- a/APIs_USB/USBSerial/main.cpp +++ b/APIs_USB/USBSerial/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" #include "USBSerial.h" +using namespace std::chrono_literals; + //Virtual serial port over USB USBSerial serial; @@ -12,6 +14,6 @@ int main(void) { while (1) { serial.printf("I am a virtual serial port\r\n"); - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } diff --git a/Tutorials_Debugging/DebugPrintf_BlinksLED/main.cpp b/Tutorials_Debugging/DebugPrintf_BlinksLED/main.cpp index 58845f8..50a40e8 100644 --- a/Tutorials_Debugging/DebugPrintf_BlinksLED/main.cpp +++ b/Tutorials_Debugging/DebugPrintf_BlinksLED/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + DigitalOut led1(LED1); int main() @@ -14,6 +16,6 @@ int main() // Print something over the serial connection printf("Blink! LED is now %d\r\n", led1.read()); - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); } } diff --git a/Tutorials_Overview/IdleLoop/main.cpp b/Tutorials_Overview/IdleLoop/main.cpp index 1189147..0b166a7 100644 --- a/Tutorials_Overview/IdleLoop/main.cpp +++ b/Tutorials_Overview/IdleLoop/main.cpp @@ -1,6 +1,8 @@ #include "mbed.h" #include "rtos_idle.h" +using namespace std::chrono_literals; + // LED for main thread DigitalOut led2(LED2); // LED for idle thread @@ -29,6 +31,6 @@ int main() { watchdogThread.start(callback(&watchdogQueue, &EventQueue::dispatch_forever)); - watchdogTicker.attach(callback(&watchdogRefreshIsr), 5); + watchdogTicker.attach(callback(&watchdogRefreshIsr), 5s); rtos_attach_idle_hook(&new_idle_loop); } diff --git a/Tutorials_SerialComm/Serial_ReadToBuffer/main.cpp b/Tutorials_SerialComm/Serial_ReadToBuffer/main.cpp index 9cb2ab1..367b178 100644 --- a/Tutorials_SerialComm/Serial_ReadToBuffer/main.cpp +++ b/Tutorials_SerialComm/Serial_ReadToBuffer/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + // Create a serial object static BufferedSerial pc(USBTX, USBRX); @@ -13,9 +15,9 @@ int main(void) char buffer[10] = {}; while (1) { if (pc.readable()) { - ThisThread::sleep_for(100); + ThisThread::sleep_for(100ms); pc.read(buffer, 10); printf("I got '%s'\n", buffer); } } -} \ No newline at end of file +} diff --git a/Tutorials_UsingAPIs/Alarm/main.cpp b/Tutorials_UsingAPIs/Alarm/main.cpp index 4e6b177..b43e8aa 100644 --- a/Tutorials_UsingAPIs/Alarm/main.cpp +++ b/Tutorials_UsingAPIs/Alarm/main.cpp @@ -4,25 +4,21 @@ */ #include "mbed.h" -// Time constants in seconds -#define HOUR 60 * 60 -#define MINUTE 60 - // Globals DigitalOut alarm_out(D2, 0); -DigitalOut alarm_led(LED_RED, 1); -DigitalOut hour_led(LED_GREEN, 1); -DigitalOut min_led(LED_BLUE, 1); +DigitalOut alarm_led(LED1, 1); +DigitalOut hour_led(LED2, 1); +DigitalOut min_led(LED3, 1); InterruptIn inc_time(BUTTON1); InterruptIn sel(BUTTON2); LowPowerTicker alarm_event; -volatile uint64_t delay = 0; -volatile uint8_t hour_count = 0; -volatile uint8_t min_count = 0; -volatile uint8_t select_state = 0; +std::chrono::hours hour_inc; +std::chrono::minutes min_inc; + +volatile uint8_t select_state = 0; // Timer Callbacks void inc_select(void) @@ -48,12 +44,10 @@ void set_time_leds(void) void inc_delay(void) { if (select_state == 0) { - delay += HOUR; - hour_count++; + hour_inc++; hour_led = !hour_led; } else { - delay += MINUTE; - min_count++; + min_inc++; min_led = !min_led; } } @@ -92,22 +86,23 @@ int main() // Sleep while waiting for user input to set the desired delay while (select_state < 2) { - ThisThread::sleep_for(10); + ThisThread::sleep_for(10ms); } // Once the delay has been input, blink back the configured hours and // minutes selected - for (uint8_t i = 0; i < hour_count * 2; i++) { + for (uint8_t i = 0; i < hour_inc.count() * 2; i++) { hour_led = !hour_led; - ThisThread::sleep_for(250); + ThisThread::sleep_for(250ms); } - for (uint8_t i = 0; i < min_count * 2; i++) { + for (uint8_t i = 0; i < min_inc.count() * 2; i++) { min_led = !min_led; - ThisThread::sleep_for(250); + ThisThread::sleep_for(250ms); } // Attach the low power ticker with the configured alarm delay + auto delay = hour_inc + min_inc; alarm_event.attach(&trigger_alarm_out, delay); // Sleep in the main thread diff --git a/Tutorials_UsingAPIs/Flow-Control-Active-Polling-Button/main.cpp b/Tutorials_UsingAPIs/Flow-Control-Active-Polling-Button/main.cpp index e0b578f..6ade906 100644 --- a/Tutorials_UsingAPIs/Flow-Control-Active-Polling-Button/main.cpp +++ b/Tutorials_UsingAPIs/Flow-Control-Active-Polling-Button/main.cpp @@ -10,7 +10,7 @@ int main() while (1) { if (BUTTON_PRESS == button) { led = !led; - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } } diff --git a/Tutorials_UsingAPIs/Flow-Control-EventQueue/main.cpp b/Tutorials_UsingAPIs/Flow-Control-EventQueue/main.cpp index 910b13a..1b28850 100644 --- a/Tutorials_UsingAPIs/Flow-Control-EventQueue/main.cpp +++ b/Tutorials_UsingAPIs/Flow-Control-EventQueue/main.cpp @@ -5,6 +5,8 @@ #include "mbed.h" +using namespace std::chrono_literals; + void flip(DigitalOut &led) { led = !led; @@ -19,8 +21,8 @@ int main() EventQueue queue; // events are simple callbacks - queue.call_every(1000, flip, led1); - queue.call_every(500, flip, led2); + queue.call_every(1s, flip, led1); + queue.call_every(500ms, flip, led2); // events are executed by the dispatch method queue.dispatch_forever(); diff --git a/Tutorials_UsingAPIs/Flow-Control-Interrupt-Button/main.cpp b/Tutorials_UsingAPIs/Flow-Control-Interrupt-Button/main.cpp index 7d51d9e..f3c1df6 100644 --- a/Tutorials_UsingAPIs/Flow-Control-Interrupt-Button/main.cpp +++ b/Tutorials_UsingAPIs/Flow-Control-Interrupt-Button/main.cpp @@ -1,5 +1,7 @@ #include "mbed.h" +using namespace std::chrono_literals; + InterruptIn button(BUTTON1); DigitalOut led(LED1); DigitalOut heartbeat(LED2); @@ -14,6 +16,6 @@ int main() button.rise(&toggle); // call toggle function on the rising edge while (1) { // wait around, interrupts will interrupt this! heartbeat = !heartbeat; - ThisThread::sleep_for(250); + ThisThread::sleep_for(250ms); } } diff --git a/Tutorials_UsingAPIs/Flow-Control-Thread/main.cpp b/Tutorials_UsingAPIs/Flow-Control-Thread/main.cpp index e6ab1fb..ecdb35a 100644 --- a/Tutorials_UsingAPIs/Flow-Control-Thread/main.cpp +++ b/Tutorials_UsingAPIs/Flow-Control-Thread/main.cpp @@ -1,5 +1,7 @@ #include "mbed.h" +using namespace std::chrono_literals; + DigitalOut led1(LED1); DigitalOut led2(LED2); Thread thread; @@ -8,7 +10,7 @@ void led2_thread() { while (true) { led2 = !led2; - ThisThread::sleep_for(1000); + ThisThread::sleep_for(1s); } } @@ -20,6 +22,6 @@ int main() while (true) { led1 = !led1; - ThisThread::sleep_for(500); + ThisThread::sleep_for(500ms); } } diff --git a/Tutorials_UsingAPIs/Flow-Control-Ticker/main.cpp b/Tutorials_UsingAPIs/Flow-Control-Ticker/main.cpp index 2e9e21a..f35ed69 100644 --- a/Tutorials_UsingAPIs/Flow-Control-Ticker/main.cpp +++ b/Tutorials_UsingAPIs/Flow-Control-Ticker/main.cpp @@ -1,5 +1,7 @@ #include "mbed.h" +using namespace std::chrono_literals; + Ticker flipper; DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -12,11 +14,11 @@ void flip() int main() { led2 = 1; - flipper.attach(&flip, 2.0); // call flip function every 2 seconds + flipper.attach(&flip, 2s); // call flip function every 2 seconds // spin in a main loop. flipper will interrupt it to call flip while (1) { led1 = !led1; - ThisThread::sleep_for(200); + ThisThread::sleep_for(200ms); } }