Added various bits, main reformatted. Added .get to class Servo to allow waiting for rotation before recording information.
Fork of Lab6_Basic by
Motor.cpp@8:c2f0e524696b, 2016-11-19 (annotated)
- Committer:
- Dogcatfee
- Date:
- Sat Nov 19 09:10:23 2016 +0000
- Revision:
- 8:c2f0e524696b
- Parent:
- 6:a64d79286726
Fixed the Motor header;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Dogcatfee | 8:c2f0e524696b | 1 | #include "mbed.h" |
Dogcatfee | 8:c2f0e524696b | 2 | #include "Motor.h" |
ziadeldebri | 3:b787aa49b900 | 3 | |
ziadeldebri | 3:b787aa49b900 | 4 | |
ziadeldebri | 3:b787aa49b900 | 5 | |
Dogcatfee | 8:c2f0e524696b | 6 | Motor::Motor(PinName Positive, PinName Negative,PinName Speed): |
Dogcatfee | 8:c2f0e524696b | 7 | _positive(Positive), _negative(Negative), _speed(Speed) { |
Dogcatfee | 8:c2f0e524696b | 8 | _speed.period(0.03f); // |
Dogcatfee | 8:c2f0e524696b | 9 | _speed.write(0.45f); |
Dogcatfee | 8:c2f0e524696b | 10 | } |
Dogcatfee | 8:c2f0e524696b | 11 | /* Input 1 or 2. |
Dogcatfee | 8:c2f0e524696b | 12 | * 1 : Postive VCC Negtaive GND, 2 : Postive GND Negtaive VCC. |
Dogcatfee | 8:c2f0e524696b | 13 | */ |
Dogcatfee | 8:c2f0e524696b | 14 | void Motor::Direction(int move) { |
Dogcatfee | 8:c2f0e524696b | 15 | if(move == 1){ |
Dogcatfee | 8:c2f0e524696b | 16 | _positive = 1; |
Dogcatfee | 8:c2f0e524696b | 17 | _negative = 0; |
Dogcatfee | 8:c2f0e524696b | 18 | } |
Dogcatfee | 8:c2f0e524696b | 19 | else if(move == 2){ |
Dogcatfee | 8:c2f0e524696b | 20 | _positive = 0; |
Dogcatfee | 8:c2f0e524696b | 21 | _negative = 1; |
ziadeldebri | 3:b787aa49b900 | 22 | } |
Dogcatfee | 8:c2f0e524696b | 23 | }//End of Direction |
ziadeldebri | 3:b787aa49b900 | 24 | |
Dogcatfee | 8:c2f0e524696b | 25 | /* No input. |
Dogcatfee | 8:c2f0e524696b | 26 | * 1 : Postive GND Negtaive GND |
Dogcatfee | 8:c2f0e524696b | 27 | */ |
Dogcatfee | 8:c2f0e524696b | 28 | void Motor::Stop() { |
Dogcatfee | 8:c2f0e524696b | 29 | _positive = 0; |
Dogcatfee | 8:c2f0e524696b | 30 | _negative = 0; |
Dogcatfee | 8:c2f0e524696b | 31 | }//End of Stop |
Dogcatfee | 8:c2f0e524696b | 32 | /* input is the . |
Dogcatfee | 8:c2f0e524696b | 33 | * 1 : Postive GND Negtaive GND |
Dogcatfee | 8:c2f0e524696b | 34 | */ |
Dogcatfee | 8:c2f0e524696b | 35 | void Motor::Speed(int motor_speed) { |
Dogcatfee | 8:c2f0e524696b | 36 | float percantage = motor_speed/100; |
Dogcatfee | 8:c2f0e524696b | 37 | _speed.write(percantage); |
Dogcatfee | 8:c2f0e524696b | 38 | }//End of Stop |