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:
- 2:ff8fd9e3d380
- Parent:
- 1:89d23c8072af
--- a/main.cpp Tue Apr 21 12:20:31 2020 +0000 +++ b/main.cpp Mon Apr 27 08:01:20 2020 +0000 @@ -1,16 +1,15 @@ #include "mbed.h" -PwmOut servo(PTA1); //servo = PTA1 +Serial uart_rx(D1, D0); //D1 = tx, D0 = rx +DigitalOut led(D2); int main() { - 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); + while(true) { + if(uart_rx.getc() == '1') { + led = 1; + thread_sleep_for(200); + led = 0; } } } \ No newline at end of file