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.
main.cpp@0:65fd20a989e9, 2016-10-07 (annotated)
- Committer:
- kmarangi
- Date:
- Fri Oct 07 11:02:23 2016 +0000
- Revision:
- 0:65fd20a989e9
- Child:
- 1:8c1e3382b4d7
test servo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kmarangi | 0:65fd20a989e9 | 1 | #include "mbed.h" |
kmarangi | 0:65fd20a989e9 | 2 | #include "Servo.h" |
kmarangi | 0:65fd20a989e9 | 3 | Serial pc(USBTX, USBRX); // USB serial interface |
kmarangi | 0:65fd20a989e9 | 4 | Servo cr_srv1(p21); // continuous rotation hobby servo right |
kmarangi | 0:65fd20a989e9 | 5 | Servo cr_srv2(p22); // continuous rotation hobby servo left |
kmarangi | 0:65fd20a989e9 | 6 | |
kmarangi | 0:65fd20a989e9 | 7 | void init_servo() { |
kmarangi | 0:65fd20a989e9 | 8 | // calibrate the servos for +/-5ms over +/-45deg |
kmarangi | 0:65fd20a989e9 | 9 | cr_srv1.calibrate(0.0005,45); |
kmarangi | 0:65fd20a989e9 | 10 | cr_srv2.calibrate(0.0005,45); |
kmarangi | 0:65fd20a989e9 | 11 | } |
kmarangi | 0:65fd20a989e9 | 12 | int main() { |
kmarangi | 0:65fd20a989e9 | 13 | |
kmarangi | 0:65fd20a989e9 | 14 | |
kmarangi | 0:65fd20a989e9 | 15 | // set the USB serial interface baud rate |
kmarangi | 0:65fd20a989e9 | 16 | pc.baud(921600); |
kmarangi | 0:65fd20a989e9 | 17 | |
kmarangi | 0:65fd20a989e9 | 18 | init_servo(); |
kmarangi | 0:65fd20a989e9 | 19 | |
kmarangi | 0:65fd20a989e9 | 20 | while(1) { |
kmarangi | 0:65fd20a989e9 | 21 | |
kmarangi | 0:65fd20a989e9 | 22 | |
kmarangi | 0:65fd20a989e9 | 23 | // sernd the servo command to the servos themselves |
kmarangi | 0:65fd20a989e9 | 24 | cr_srv1.write(0.6); // write to the continuous rotation servo1 |
kmarangi | 0:65fd20a989e9 | 25 | cr_srv2.write(0.4); // write to the continous servo2 |
kmarangi | 0:65fd20a989e9 | 26 | |
kmarangi | 0:65fd20a989e9 | 27 | } |
kmarangi | 0:65fd20a989e9 | 28 | } |
kmarangi | 0:65fd20a989e9 | 29 | |
kmarangi | 0:65fd20a989e9 | 30 |