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.
Dependencies: mbed
main.cpp@2:80b1aa8ca93d, 2020-05-30 (annotated)
- Committer:
- saeichi
- Date:
- Sat May 30 08:00:31 2020 +0000
- Revision:
- 2:80b1aa8ca93d
- Parent:
- 1:0e1cdc344b27
servomotor_nucleo
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| usshi | 0:19d128ee3b65 | 1 | #include "mbed.h" |
| usshi | 0:19d128ee3b65 | 2 | |
| saeichi | 2:80b1aa8ca93d | 3 | PwmOut servo(A5); |
| saeichi | 2:80b1aa8ca93d | 4 | Serial pc(SERIAL_TX, SERIAL_RX); |
| usshi | 0:19d128ee3b65 | 5 | |
| usshi | 0:19d128ee3b65 | 6 | float calc(float); |
| usshi | 0:19d128ee3b65 | 7 | int main() |
| usshi | 0:19d128ee3b65 | 8 | { |
| usshi | 0:19d128ee3b65 | 9 | float a,b; |
| usshi | 0:19d128ee3b65 | 10 | servo.period_ms(20); |
| usshi | 0:19d128ee3b65 | 11 | wait_ms(100); |
| usshi | 0:19d128ee3b65 | 12 | pc.printf("\r\n---servo test---\n\r"); |
| usshi | 0:19d128ee3b65 | 13 | while(1) { |
| usshi | 0:19d128ee3b65 | 14 | pc.printf("degree(-90~90) : "); |
| igarashi50 | 1:0e1cdc344b27 | 15 | pc.scanf("%f",&a); |
| usshi | 0:19d128ee3b65 | 16 | if(-90<=a&&a<=90) { |
| usshi | 0:19d128ee3b65 | 17 | b=calc(a); |
| igarashi50 | 1:0e1cdc344b27 | 18 | pc.printf("%f PWM:%f\r\n",a,b); |
| usshi | 0:19d128ee3b65 | 19 | servo.pulsewidth(b); |
| usshi | 0:19d128ee3b65 | 20 | } else { |
| usshi | 0:19d128ee3b65 | 21 | break; |
| usshi | 0:19d128ee3b65 | 22 | } |
| usshi | 0:19d128ee3b65 | 23 | } |
| usshi | 0:19d128ee3b65 | 24 | return 0; |
| usshi | 0:19d128ee3b65 | 25 | } |
| usshi | 0:19d128ee3b65 | 26 | |
| usshi | 0:19d128ee3b65 | 27 | float calc(float x) |
| usshi | 0:19d128ee3b65 | 28 | { |
| usshi | 0:19d128ee3b65 | 29 | return (1.45+(2.4-0.5)/180*x)/1000; |
| usshi | 0:19d128ee3b65 | 30 | } |