![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
shoot
Dependencies: mbed SBDBT arrc_mbed Servo air
main.cpp
- Committer:
- asumamatsumura
- Date:
- 2022-02-24
- Revision:
- 2:0428390d7c90
- Parent:
- 1:cae30876c429
File content as of revision 2:0428390d7c90:
#include "mbed.h" #include "air.hpp" #include "sbdbt.hpp" #include "Servo.h" sbdbt ds3(A0, A1); DigitalIn limitA(PA_9,PullUp); Air hassya(PA_0); Servo myservo(PB_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){ if(data==0){ myservo = 0; }else{ myservo = 0.2; } } //↓発射用 void Hassya(bool data,int tim){ if(data==1 || timer.read_ms()-tim<3000){ if(timer.read_ms()-tim>2000){ hassya.move(1); }else{ hassya.move(0); } if(timer.read_ms()-tim>1000) Servo(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 || limitA)){ shoot=!shoot; tim=timer.read_ms(); } old_square=ds3.square(); //関数 Hassya(shoot,tim); } }