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
- Committer:
- usshi
- Date:
- 2018-05-29
- Revision:
- 0:19d128ee3b65
- Child:
- 1:0e1cdc344b27
File content as of revision 0:19d128ee3b65:
#include "mbed.h"
PwmOut servo(p21);
Serial pc(USBTX,USBRX);
float calc(float);
int main()
{
float a,b;
servo.period_ms(20);
wait_ms(100);
pc.printf("\r\n---servo test---\n\r");
while(1) {
pc.printf("degree(-90~90) : ");
scanf("%f",&a);
if(-90<=a&&a<=90) {
b=calc(a);
printf("%f PWM:%f\r\n",a,b);
servo.pulsewidth(b);
} else {
break;
}
}
return 0;
}
float calc(float x)
{
return (1.45+(2.4-0.5)/180*x)/1000;
}