Skip to content

Update for deprecation of non-Chrono timing APIs #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion APIs_Drivers/AnalogIn_ex_2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "mbed.h"

using namespace std::chrono_literals;

AnalogIn input(A0);

#define NUM_SAMPLES 1024
Expand All @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion APIs_Drivers/AnalogIn_ex_3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
6 changes: 4 additions & 2 deletions APIs_Drivers/AnalogOut_ex_2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
}
}
6 changes: 4 additions & 2 deletions APIs_Drivers/BusInOut_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

#include "mbed.h"

using namespace std::chrono_literals;

BusInOut pins(D0, D1, D2); // Change these pins to buttons on your board.

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");
}
Expand Down
4 changes: 3 additions & 1 deletion APIs_Drivers/BusIn_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
}
4 changes: 3 additions & 1 deletion APIs_Drivers/BusOut_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

#include "mbed.h"

using namespace std::chrono_literals;

BusOut myleds(LED1, LED2, LED3, LED4);

int main()
{
while (1) {
for (int i = 0; i < 16; i++) {
myleds = i;
ThisThread::sleep_for(250);
ThisThread::sleep_for(250ms);
}
}
}
3 changes: 2 additions & 1 deletion APIs_Drivers/CAN_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "mbed.h"

using namespace std::chrono_literals;

Ticker ticker;
DigitalOut led1(LED1);
Expand Down Expand Up @@ -43,7 +44,7 @@ int main()
printf("Message received: %d\n", msg.data[0]);
led2 = !led2;
}
ThisThread::sleep_for(200);
ThisThread::sleep_for(200ms);
}
}

6 changes: 4 additions & 2 deletions APIs_Drivers/DigitalInOut_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "mbed.h"

using namespace std::chrono_literals;

DigitalInOut mypin(LED1);

int main()
Expand All @@ -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);
}
}
4 changes: 3 additions & 1 deletion APIs_Drivers/DigitalIn_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
}
6 changes: 4 additions & 2 deletions APIs_Drivers/DigitalOut_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "mbed.h"

using namespace std::chrono_literals;

DigitalOut myled(LED1);

int main()
Expand All @@ -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);
}
}
4 changes: 3 additions & 1 deletion APIs_Drivers/I2C_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "mbed.h"

using namespace std::chrono_literals;

// Read temperature from LM75BD

I2C i2c(I2C_SDA, I2C_SCL);
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion APIs_Drivers/InterruptIn_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,6 +35,6 @@ int main()
{
while (1) {
printf("Count so far: %d\n", counter.read());
ThisThread::sleep_for(2000);
ThisThread::sleep_for(2s);
}
}
4 changes: 3 additions & 1 deletion APIs_Drivers/InterruptIn_ex_2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "mbed.h"

using namespace std::chrono_literals;

InterruptIn button(SW2);
DigitalOut led(LED1);
DigitalOut flash(LED4);
Expand All @@ -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);
}
}
6 changes: 4 additions & 2 deletions APIs_Drivers/PortIn_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
6 changes: 4 additions & 2 deletions APIs_Drivers/PortOut_ex_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
4 changes: 3 additions & 1 deletion APIs_Drivers/QSPI/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions APIs_Drivers/Ticker_Example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#include "mbed.h"

using namespace std::chrono_literals;

// A class for flip()-ing a DigitalOut
class Flipper {
public:
Expand All @@ -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);
}
}
6 changes: 4 additions & 2 deletions APIs_Drivers/Ticker_HelloWorld/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#include "mbed.h"

using namespace std::chrono_literals;

Ticker flipper;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Expand All @@ -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);
}
}
6 changes: 4 additions & 2 deletions APIs_Drivers/Timeout_Example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#include "mbed.h"

using namespace std::chrono_literals;

// A class for flip()-ing a DigitalOut
class Flipper {
public:
Expand All @@ -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);
}
}
6 changes: 4 additions & 2 deletions APIs_Drivers/Timeout_HelloWorld/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#include "mbed.h"

using namespace std::chrono_literals;

Timeout flipper;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Expand All @@ -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);
}
}
Loading