![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
kakuninonegai
Dependencies: mbed SBDBT arrc_mbed air
main.cpp@0:b03df060dbea, 2022-01-18 (annotated)
- Committer:
- asumamatsumura
- Date:
- Tue Jan 18 08:27:37 2022 +0000
- Revision:
- 0:b03df060dbea
- Child:
- 1:bf629e5bf337
no-sakumotu kaisyu-
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
asumamatsumura | 0:b03df060dbea | 1 | #include "mbed.h" |
asumamatsumura | 0:b03df060dbea | 2 | #include "scrp_slave.hpp" |
asumamatsumura | 0:b03df060dbea | 3 | #include "air.hpp" |
asumamatsumura | 0:b03df060dbea | 4 | #include "sbdbt.hpp" |
asumamatsumura | 0:b03df060dbea | 5 | sbdbt ds3(A0, A1); |
asumamatsumura | 0:b03df060dbea | 6 | DigitalIn limitA(PA_9,PullUp); |
asumamatsumura | 0:b03df060dbea | 7 | DigitalIn limitB(PC_5,PullUp); |
asumamatsumura | 0:b03df060dbea | 8 | Air catch_no(PA_0); |
asumamatsumura | 0:b03df060dbea | 9 | |
asumamatsumura | 0:b03df060dbea | 10 | void driveMotorS(double pwm){ |
asumamatsumura | 0:b03df060dbea | 11 | PwmOut up_pin_A(PB_13); |
asumamatsumura | 0:b03df060dbea | 12 | PwmOut up_pin_B(PB_14); |
asumamatsumura | 0:b03df060dbea | 13 | up_pin_A.period_us(2048); |
asumamatsumura | 0:b03df060dbea | 14 | up_pin_B.period_us(2048); |
asumamatsumura | 0:b03df060dbea | 15 | if (!pwm) { |
asumamatsumura | 0:b03df060dbea | 16 | up_pin_A = 0; |
asumamatsumura | 0:b03df060dbea | 17 | up_pin_B = 0; |
asumamatsumura | 0:b03df060dbea | 18 | } else if (0 < pwm) { |
asumamatsumura | 0:b03df060dbea | 19 | up_pin_A = pwm; |
asumamatsumura | 0:b03df060dbea | 20 | up_pin_B = 0; |
asumamatsumura | 0:b03df060dbea | 21 | } else { |
asumamatsumura | 0:b03df060dbea | 22 | up_pin_A = 0; |
asumamatsumura | 0:b03df060dbea | 23 | up_pin_B= -pwm; |
asumamatsumura | 0:b03df060dbea | 24 | } |
asumamatsumura | 0:b03df060dbea | 25 | } |
asumamatsumura | 0:b03df060dbea | 26 | void Up(int data){ |
asumamatsumura | 0:b03df060dbea | 27 | if(data==1 && !limitA){ |
asumamatsumura | 0:b03df060dbea | 28 | driveMotorS(0.06); |
asumamatsumura | 0:b03df060dbea | 29 | }else if(data==-1 && !limitB){ |
asumamatsumura | 0:b03df060dbea | 30 | driveMotorS(-0.06); |
asumamatsumura | 0:b03df060dbea | 31 | }else{ |
asumamatsumura | 0:b03df060dbea | 32 | driveMotorS(0); |
asumamatsumura | 0:b03df060dbea | 33 | } |
asumamatsumura | 0:b03df060dbea | 34 | } |
asumamatsumura | 0:b03df060dbea | 35 | void CATCH_NO(bool data){ |
asumamatsumura | 0:b03df060dbea | 36 | catch_no.move(data); |
asumamatsumura | 0:b03df060dbea | 37 | } |
asumamatsumura | 0:b03df060dbea | 38 | |
asumamatsumura | 0:b03df060dbea | 39 | int main(){ |
asumamatsumura | 0:b03df060dbea | 40 | int up; |
asumamatsumura | 0:b03df060dbea | 41 | bool catch_no=0,old_circle; |
asumamatsumura | 0:b03df060dbea | 42 | while(true){ |
asumamatsumura | 0:b03df060dbea | 43 | up=ds3.up()+ds3.down(); |
asumamatsumura | 0:b03df060dbea | 44 | if(old_circle<ds3.circle()) catch_no=!catch_no; |
asumamatsumura | 0:b03df060dbea | 45 | old_circle=ds3.circle(); |
asumamatsumura | 0:b03df060dbea | 46 | |
asumamatsumura | 0:b03df060dbea | 47 | Up(up); |
asumamatsumura | 0:b03df060dbea | 48 | CATCH_NO(catch_no); |
asumamatsumura | 0:b03df060dbea | 49 | } |
asumamatsumura | 0:b03df060dbea | 50 | } |