サーボモータの動作確認プログラム

Dependencies:   mbed

Revision:
0:19d128ee3b65
Child:
1:0e1cdc344b27
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 29 08:00:38 2018 +0000
@@ -0,0 +1,30 @@
+#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;
+}