I was teaching IoT using Mbed for 3 semesters.
The Mbed is keep upgrading so I need to modify my lecture notes.
This semester I modify my lecture to Mbed 6.3.
I find the time function will confuse the student.
For example, the below code using different time functions.
The project can be compiled successfully.
Some student’s projects don’t work on a Chrono duration, ThisThread::sleep_for (3ms);
But can work on ThisThread::sleep_for (3000);
It is because of the Version of Mbed in their project?
Do you provide the latest Example project with the latest Mbed OS?
The example on your web seems not the latest OS?
#include "mbed.h"
PwmOut servo(PA_6);
int main() {
servo.period_us(20000); //20ms period, typical for analog RC servo
int servopulsewidth=1450;
servo.pulsewidth_us(servopulsewidth); //centers the servo. servos range is from 500 to 2400us.
wait_us(3000);
//ThisThread::sleep_for (3ms);
while(1){
servo.pulsewidth_us(500); //0deg
ThisThread::sleep_for (3000);
servo.pulsewidth_us(1450); //90deg
ThisThread::sleep_for (3s);
servo.pulsewidth_us(2400); //180deg
ThisThread::sleep_for (3s);
servo.pulsewidth_us(1450); //90deg
}
}