raspai

Dependencies:   mbed SBDBT arrc_mbed Servo air

Revision:
0:b68d87850401
Child:
1:1766ac88bf57
diff -r 000000000000 -r b68d87850401 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 25 04:50:23 2022 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+#include "air.hpp"
+#include "Servo.h"
+#include "scrp_slave.hpp"
+ScrpSlave slave(PC_12,PD_2,PH_1,SERIAL_TX,SERIAL_RX,0x0807ffff);
+Serial pc(SERIAL_TX,SERIAL_RX);
+DigitalIn limitA(PA_9,PullUp);
+Air hassya(PA_0);
+DigitalOut Led1(PA_10);
+DigitalOut Led2(PB_15);
+DigitalOut Led3(PB_2);
+Servo myservo(PB_0);
+Timer timer;
+int tim=-3000;
+//↓モータ用
+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){
+    if(data==0){
+    myservo = 0;
+    }else{
+    myservo = 0.2;
+    }
+}
+//↓発射用
+bool Hassya(int rx_data,int &tx_data){
+    if(rx_data == 1 && limitA==0){
+        tim=timer.read_ms();
+    }
+    if(timer.read_ms()-tim<1000){
+            hassya.move(1);
+            driveMotorS(0);
+            Servo(1);
+            Led1.write(1);
+            Led2.write(0);
+            Led3.write(1);
+    }else if(timer.read_ms()-tim<2000){
+            hassya.move(0);
+            driveMotorS(0);
+            Servo(0);
+            Led1.write(0);
+            Led2.write(0);
+            Led3.write(0);
+    }else if(timer.read_ms()-tim>2000 && limitA==1){
+            hassya.move(0);
+            driveMotorS(0.06);
+            Servo(0);
+            Led1.write(0);
+            Led2.write(1);
+            Led3.write(0);
+    }else {
+            hassya.move(1);
+            driveMotorS(0);
+            Servo(0);
+            Led1.write(1);
+            Led2.write(0);
+            Led3.write(0);
+    }
+    return true;
+}
+int main(){
+    timer.start();
+    slave.addCMD(6,Hassya);
+    while(true);
+}
\ No newline at end of file