![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
program_of_Monday
main.cpp@0:2da7c2bc2ed5, 2021-11-18 (annotated)
- Committer:
- kaipon
- Date:
- Thu Nov 18 21:30:45 2021 +0000
- Revision:
- 0:2da7c2bc2ed5
getuyo yoru no yatu
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaipon | 0:2da7c2bc2ed5 | 1 | #include "mbed.h" |
kaipon | 0:2da7c2bc2ed5 | 2 | PwmOut pinAFin(D10); |
kaipon | 0:2da7c2bc2ed5 | 3 | PwmOut pinARin(A1); |
kaipon | 0:2da7c2bc2ed5 | 4 | PwmOut pinBFin(D11); |
kaipon | 0:2da7c2bc2ed5 | 5 | PwmOut pinBRin(D12); |
kaipon | 0:2da7c2bc2ed5 | 6 | |
kaipon | 0:2da7c2bc2ed5 | 7 | void driveMotor(int speedA,int speedB) { |
kaipon | 0:2da7c2bc2ed5 | 8 | float outputA = abs(speedA); |
kaipon | 0:2da7c2bc2ed5 | 9 | float outputB = abs(speedB); |
kaipon | 0:2da7c2bc2ed5 | 10 | if (speedA > 0) { |
kaipon | 0:2da7c2bc2ed5 | 11 | pinAFin=outputA; |
kaipon | 0:2da7c2bc2ed5 | 12 | pinARin=0; |
kaipon | 0:2da7c2bc2ed5 | 13 | } else if (speedA < 0) { |
kaipon | 0:2da7c2bc2ed5 | 14 | pinAFin=0; |
kaipon | 0:2da7c2bc2ed5 | 15 | pinARin=outputA; |
kaipon | 0:2da7c2bc2ed5 | 16 | } else { |
kaipon | 0:2da7c2bc2ed5 | 17 | pinAFin=0; |
kaipon | 0:2da7c2bc2ed5 | 18 | pinARin=0; |
kaipon | 0:2da7c2bc2ed5 | 19 | } |
kaipon | 0:2da7c2bc2ed5 | 20 | if (speedB > 0) { |
kaipon | 0:2da7c2bc2ed5 | 21 | pinBFin=outputB; |
kaipon | 0:2da7c2bc2ed5 | 22 | pinBRin=0; |
kaipon | 0:2da7c2bc2ed5 | 23 | } else if (speedB < 0) { |
kaipon | 0:2da7c2bc2ed5 | 24 | pinBFin=0; |
kaipon | 0:2da7c2bc2ed5 | 25 | pinBRin=outputB; |
kaipon | 0:2da7c2bc2ed5 | 26 | } else { |
kaipon | 0:2da7c2bc2ed5 | 27 | pinBFin=0; |
kaipon | 0:2da7c2bc2ed5 | 28 | pinBRin=0; |
kaipon | 0:2da7c2bc2ed5 | 29 | } |
kaipon | 0:2da7c2bc2ed5 | 30 | } |
kaipon | 0:2da7c2bc2ed5 | 31 | |
kaipon | 0:2da7c2bc2ed5 | 32 | int main() |
kaipon | 0:2da7c2bc2ed5 | 33 | { |
kaipon | 0:2da7c2bc2ed5 | 34 | |
kaipon | 0:2da7c2bc2ed5 | 35 | wait(10); |
kaipon | 0:2da7c2bc2ed5 | 36 | driveMotor(1,1); |
kaipon | 0:2da7c2bc2ed5 | 37 | wait(10); |
kaipon | 0:2da7c2bc2ed5 | 38 | driveMotor(0,0); |
kaipon | 0:2da7c2bc2ed5 | 39 | return 0; |
kaipon | 0:2da7c2bc2ed5 | 40 | |
kaipon | 0:2da7c2bc2ed5 | 41 | } |
kaipon | 0:2da7c2bc2ed5 | 42 |