STM32でDS5160を動かすプログラム

Dependencies:   mbed Servo

Files at this revision

API Documentation at this revision

Comitter:
hosei2
Date:
Thu Oct 15 14:49:28 2020 +0000
Commit message:
initialCommit

Changed in this revision

Servo.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Thu Oct 15 14:49:28 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 15 14:49:28 2020 +0000
@@ -0,0 +1,69 @@
+#include "mbed.h"
+#include "Servo.h"
+DigitalOut SV(PA_1);// MOSFET制御用(サーボ)
+DigitalOut dump(PA_14);// MOSFET制御用(電磁弁)
+DigitalOut L1(PA_4);//LED用ピン
+DigitalOut L2(PA_5);
+DigitalOut L3(PA_6);
+DigitalOut out1(PB_0);//動作確認用ピン
+DigitalOut out2(PB_1);
+DigitalOut out3(PA_7);
+DigitalIn TWE(PB_7);//TWEの入力の端子(サーボ)
+//DigitalIn TWE(PB_5);//TWEの入力の端子(電磁弁)
+PwmOut pwm(PA_8);//サーボモーターの端子
+//int caunt;//動作を一度しか行わないための関数
+int stop_time=10;//バルブをあけている時間(秒)
+int start=500, end=1500;//startが基準位置、endが動作後の停止位置、start:500,end:1500の時サーボの回転角が約90度、start:500,end:2400の時サーボの回転角が約180度
+    
+int main() {
+    
+        //caunt=0;
+        SV=1;//サーボ用電源オン
+        //↓サーボモーターの初期位置への移動
+        for(int p = end; p >=start; p -= 10) {
+        pwm.pulsewidth_us(p);
+        wait_ms(20);//15辺りが限界
+        }
+        SV=0;//サーボ用電源オフ
+        
+    while(1){
+        if(dump==0){
+            }
+            
+        if(TWE==1){
+        L1=1;//待機LED点灯
+        out1=1;//subSTMに待機の信号を送る
+        }  
+        
+        if(TWE==0){
+            SV=1;//サーボ用電源オン
+            out1=0;//待機信号を消す
+            out2=1;//動作1信号を送る
+            for(int p = start; p < end; p += 10) {
+            pwm.pulsewidth_us(p);
+            wait_ms(20);
+            L1=0;//待機LED消灯
+            L2=1;//動作LED点灯
+            }
+                
+            wait(stop_time);
+            out2=0;//動作1信号を消す    
+            out3=1;//動作2信号を送る
+            
+            for(int p = end; p >=start; p -= 10) {
+            pwm.pulsewidth_us(p);
+            wait_ms(20);
+            L3=1;//終了LED点灯
+            L2=0;//動作LED消灯
+            }
+            
+            wait(5);
+            out3=0;//動作2信号を消す
+            //caunt=1;
+            SV=0;//サーボ用電源オフ
+            out1=1;//待機信号を送る
+            L3=0;
+            }
+
+            }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 15 14:49:28 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file