Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Actuator/Motor.cpp@1:d43df9a7cef2, 2020-10-31 (annotated)
- Committer:
- yeongsookim
- Date:
- Sat Oct 31 07:12:28 2020 +0000
- Revision:
- 1:d43df9a7cef2
- Parent:
- 0:3ead6014ad51
2020 Hall Sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yeongsookim | 0:3ead6014ad51 | 1 | #include "Motor.h" |
yeongsookim | 0:3ead6014ad51 | 2 | |
yeongsookim | 0:3ead6014ad51 | 3 | |
yeongsookim | 0:3ead6014ad51 | 4 | Motor::Motor(PinName IN1, PinName IN2, PinName INH1, PinName INH2) |
yeongsookim | 0:3ead6014ad51 | 5 | : IN1_(IN1), IN2_(IN2), INH1_(INH1), INH2_(INH2) |
yeongsookim | 0:3ead6014ad51 | 6 | { |
yeongsookim | 0:3ead6014ad51 | 7 | INH1_=1; |
yeongsookim | 0:3ead6014ad51 | 8 | INH2_=1; |
yeongsookim | 1:d43df9a7cef2 | 9 | IN1_.period_us(100); |
yeongsookim | 1:d43df9a7cef2 | 10 | IN2_.period_us(100); |
yeongsookim | 0:3ead6014ad51 | 11 | } |
yeongsookim | 0:3ead6014ad51 | 12 | |
yeongsookim | 0:3ead6014ad51 | 13 | void Motor::setSpeed_percent(float percent, char direction) |
yeongsookim | 0:3ead6014ad51 | 14 | { |
yeongsookim | 0:3ead6014ad51 | 15 | float duty = percent/100.0; |
yeongsookim | 0:3ead6014ad51 | 16 | if(duty>1.0) { |
yeongsookim | 0:3ead6014ad51 | 17 | duty=1.0; |
yeongsookim | 0:3ead6014ad51 | 18 | } else if(duty<0.0) { |
yeongsookim | 0:3ead6014ad51 | 19 | duty=0.0; |
yeongsookim | 0:3ead6014ad51 | 20 | } |
yeongsookim | 0:3ead6014ad51 | 21 | |
yeongsookim | 0:3ead6014ad51 | 22 | if(direction==FORWARD) |
yeongsookim | 0:3ead6014ad51 | 23 | { |
yeongsookim | 0:3ead6014ad51 | 24 | IN1_=0; |
yeongsookim | 0:3ead6014ad51 | 25 | IN2_=duty; |
yeongsookim | 0:3ead6014ad51 | 26 | } |
yeongsookim | 0:3ead6014ad51 | 27 | else if (direction == BACKWARD){ |
yeongsookim | 0:3ead6014ad51 | 28 | IN1_=duty; |
yeongsookim | 0:3ead6014ad51 | 29 | IN2_=0; |
yeongsookim | 0:3ead6014ad51 | 30 | } |
yeongsookim | 1:d43df9a7cef2 | 31 | else if (direction == BRAKE) |
yeongsookim | 0:3ead6014ad51 | 32 | { |
yeongsookim | 0:3ead6014ad51 | 33 | IN1_=1; |
yeongsookim | 0:3ead6014ad51 | 34 | IN2_=1; |
yeongsookim | 0:3ead6014ad51 | 35 | } |
yeongsookim | 0:3ead6014ad51 | 36 | else |
yeongsookim | 0:3ead6014ad51 | 37 | { |
yeongsookim | 0:3ead6014ad51 | 38 | IN1_=0; |
yeongsookim | 0:3ead6014ad51 | 39 | IN2_=0; |
yeongsookim | 0:3ead6014ad51 | 40 | } |
yeongsookim | 0:3ead6014ad51 | 41 | } |