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@3:b787aa49b900, 2016-09-19 (annotated)
- Committer:
- ziadeldebri
- Date:
- Mon Sep 19 17:06:45 2016 +0000
- Revision:
- 3:b787aa49b900
- Child:
- 6:a64d79286726
Scott Test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ziadeldebri | 3:b787aa49b900 | 1 | #include "mbed.h" |
ziadeldebri | 3:b787aa49b900 | 2 | #include "Motor.h" |
ziadeldebri | 3:b787aa49b900 | 3 | |
ziadeldebri | 3:b787aa49b900 | 4 | |
ziadeldebri | 3:b787aa49b900 | 5 | |
ziadeldebri | 3:b787aa49b900 | 6 | Motor::Motor(PinName Positive, PinName Negative,PinName Speed): |
ziadeldebri | 3:b787aa49b900 | 7 | _positive(Positive), _negative(Negative), _speed(Speed) { |
ziadeldebri | 3:b787aa49b900 | 8 | _speed.period(0.03f); // |
ziadeldebri | 3:b787aa49b900 | 9 | _speed.write(0.45f); |
ziadeldebri | 3:b787aa49b900 | 10 | } |
ziadeldebri | 3:b787aa49b900 | 11 | /* Input 1 or 2. |
ziadeldebri | 3:b787aa49b900 | 12 | * 1 : Postive VCC Negtaive GND, 2 : Postive GND Negtaive VCC. |
ziadeldebri | 3:b787aa49b900 | 13 | */ |
ziadeldebri | 3:b787aa49b900 | 14 | void Motor::Direction(int move) { |
ziadeldebri | 3:b787aa49b900 | 15 | if(move == 1){ |
ziadeldebri | 3:b787aa49b900 | 16 | _positive = 1; |
ziadeldebri | 3:b787aa49b900 | 17 | _negative = 0; |
ziadeldebri | 3:b787aa49b900 | 18 | } |
ziadeldebri | 3:b787aa49b900 | 19 | else if(move == 2){ |
ziadeldebri | 3:b787aa49b900 | 20 | _positive = 0; |
ziadeldebri | 3:b787aa49b900 | 21 | _negative = 1; |
ziadeldebri | 3:b787aa49b900 | 22 | } |
ziadeldebri | 3:b787aa49b900 | 23 | }//End of Direction |
ziadeldebri | 3:b787aa49b900 | 24 | |
ziadeldebri | 3:b787aa49b900 | 25 | /* No input. |
ziadeldebri | 3:b787aa49b900 | 26 | * 1 : Postive GND Negtaive GND |
ziadeldebri | 3:b787aa49b900 | 27 | */ |
ziadeldebri | 3:b787aa49b900 | 28 | void Motor::Stop() { |
ziadeldebri | 3:b787aa49b900 | 29 | _positive = 0; |
ziadeldebri | 3:b787aa49b900 | 30 | _negative = 0; |
ziadeldebri | 3:b787aa49b900 | 31 | }//End of Stop |
ziadeldebri | 3:b787aa49b900 | 32 | /* input is the . |
ziadeldebri | 3:b787aa49b900 | 33 | * 1 : Postive GND Negtaive GND |
ziadeldebri | 3:b787aa49b900 | 34 | */ |
ziadeldebri | 3:b787aa49b900 | 35 | void Motor::Speed(int motor_speed) { |
ziadeldebri | 3:b787aa49b900 | 36 | float percantage = motor_speed/100; |
ziadeldebri | 3:b787aa49b900 | 37 | _speed.write(percantage); |
ziadeldebri | 3:b787aa49b900 | 38 | }//End of Stop |