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:
- igarashi50
- Date:
- 2018-06-29
- Revision:
- 1:0e1cdc344b27
- Parent:
- 0:19d128ee3b65
- Child:
- 2:80b1aa8ca93d
File content as of revision 1:0e1cdc344b27:
#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) : ");
pc.scanf("%f",&a);
if(-90<=a&&a<=90) {
b=calc(a);
pc.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;
}