shoot

Dependencies:   mbed SBDBT arrc_mbed Servo air

Revision:
0:6f9a457b09e1
Child:
1:cae30876c429
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 19 08:37:40 2022 +0000
@@ -0,0 +1,59 @@
+#include "mbed.h"
+#include "air.hpp"
+#include "sbdbt.hpp"
+sbdbt ds3(A0, A1);
+DigitalIn limitA(PA_9,PullUp);
+Air hassya(PA_0);
+Timer timer;
+//↓モータ用
+void driveMotorS(double pwm){
+    PwmOut up_pin_A(PB_13);
+    PwmOut up_pin_B(PB_14);
+    up_pin_A.period_us(2048);
+    up_pin_B.period_us(2048);
+    if (!pwm) {
+        up_pin_A = 0;
+        up_pin_B = 0;
+    } else if (0 < pwm) {
+        up_pin_A = pwm;
+        up_pin_B = 0;
+    } else {
+        up_pin_A = 0;
+        up_pin_B= -pwm;
+    }
+}
+// ↓サーボ用(未実装)
+void Servo(bool data){
+    
+    }
+//↓発射用
+void Hassya(bool data,int tim){
+    if((data==1 || timer.read_ms()-tim<3000) && limitA){
+        hassya.move(0);
+        if(timer.read_ms()-tim>1000) Servo(1);
+        if(timer.read_ms()-tim>2000) hassya.move(1);
+    }else{
+        if(limitA){
+            driveMotorS(0);
+            Servo(0);
+        }else{
+            driveMotorS(0.06);
+        }
+    }
+}
+int main(){
+    //↓宣言
+    bool shoot;
+    int tim,old_square=0;
+    timer.start();
+    while(true){
+        //コントローラ関係
+        if(old_square<ds3.square()){
+            shoot=!shoot;
+            tim=timer.read_ms();
+        }
+        old_square=ds3.square();
+        //関数
+        Hassya(shoot,tim);
+        }
+}
\ No newline at end of file