Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:89d23c8072af
- Parent:
- 0:f31836d48420
- Child:
- 2:20e20cfae75e
diff -r f31836d48420 -r 89d23c8072af main.cpp --- a/main.cpp Sun Mar 29 19:41:28 2020 +0000 +++ b/main.cpp Tue Apr 21 12:20:31 2020 +0000 @@ -1,18 +1,16 @@ #include "mbed.h" -// https://os.mbed.com/docs/mbed-os/v5.15/tools/creating-a-new-program.html - -Serial pc(USBTX, USBRX, 115200); // baud rate 115200 -DigitalOut led(LED1); // led = LED1 +PwmOut servo(PTA1); //servo = PTA1 int main() { - while (true) { - led = 0; - printf("LED1 is ON\r\n"); - thread_sleep_for(500); - led = 1; - printf("LED1 is OFF\r\n"); - thread_sleep_for(500); + float w; + + servo.period(20.0 / 1000.0); //period = 20ms for SG90 servo + while (true) { //500 ~ 2500us for degree 0 to 180 + for(w = 500; w <= 2500; w += 100) { + servo.write(w / (20.0 * 1000.0)); + thread_sleep_for(1000); + } } } \ No newline at end of file