サーボモーターの動作確認プログラム(nucleo版)

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
taquto
Date:
Sat Aug 31 07:45:12 2024 +0000
Parent:
2:80b1aa8ca93d
Commit message:
??????

Changed in this revision

main_access_servo_tougou.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 80b1aa8ca93d -r cf99afcea25f main_access_servo_tougou.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_access_servo_tougou.cpp	Sat Aug 31 07:45:12 2024 +0000
@@ -0,0 +1,82 @@
+#include "mbed.h"
+
+PwmOut servo(PB_6);
+DigitalIn push(PA_6);
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+
+float calc(float);
+int a,k,count;
+int main()
+{    
+     servo.period_ms(20);
+    servo.pulsewidth((1.45+(2.4-0.5)/180*90)/1000); //90度回転
+    k=1;
+    a=0;
+    while(1) {
+
+       pc.printf("a=%d\r\n",a);
+/*
+       if(push == 1){
+           a=1; //押された証拠
+              
+           while(push != 1){
+            count = 0;
+            wait(0.3); //チャタリング対策
+           }
+           while(push == 1){
+            count ++;
+            wait(0.3); //チャタリング対策
+           }
+        }
+
+        pc.printf("a=%d\r\n",a);
+
+        if(a == 1){
+            if(k == 0){
+                servo.pulsewidth((1.45+(2.4-0.5)/180*90)/1000); //90度回転
+                k=1;
+            }
+            else if(k == 1){
+                servo.pulsewidth((1.45+(2.4-0.5)/180*0)/1000); //0度回転
+                k=0;
+            }
+            a=0;
+        }*/
+
+        if(push==1){
+            a=1;
+        }
+
+        if(a==1){
+            if(push==0){
+                a = 2; //スイッチ押された判定
+                wait(0.3); //チャタリング対策
+            }
+        }
+
+        if(k == 0){
+            if(a == 2){
+                servo.pulsewidth((1.45+(2.4-0.5)/180*90)/1000); //90度回転
+                k = 1;
+                a = 0;
+            }
+        }
+        else if(k == 1){
+            if(a == 2){
+                servo.pulsewidth((1.45+(2.4-0.5)/180*0)/1000); //0度回転
+                k = 0;
+                a = 0;
+            }
+        }
+           
+    }       
+    return 0;
+}
+
+/*
+float calc(float x)
+{
+    return (1.45+(2.4-0.5)/180*x)/1000;
+}
+*/
\ No newline at end of file