Added various bits, main reformatted. Added .get to class Servo to allow waiting for rotation before recording information.
Fork of Lab6_Basic by
Motor.h@6:a64d79286726, 2016-11-19 (annotated)
- Committer:
- Dogcatfee
- Date:
- Sat Nov 19 08:32:04 2016 +0000
- Revision:
- 6:a64d79286726
- Parent:
- 3:b787aa49b900
- Child:
- 8:c2f0e524696b
Added while/if statement to wait for rotation before recording.; Added .get() to Servo class, returns unsigned int of approximated rotation.; Added const int size to change size of arrays and loops; Added position_array with for fill.; Reformatted main.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Dogcatfee | 6:a64d79286726 | 1 | #include "Motor.h" |
ziadeldebri | 3:b787aa49b900 | 2 | #include "mbed.h" |
Dogcatfee | 6:a64d79286726 | 3 | #include "SLCD.h" |
Dogcatfee | 6:a64d79286726 | 4 | #ifndef MBED_SERVO_H |
Dogcatfee | 6:a64d79286726 | 5 | #define MBED_SERVO_H |
Dogcatfee | 6:a64d79286726 | 6 | |
Dogcatfee | 6:a64d79286726 | 7 | /** Servo control class, based on a Motor Class object |
Dogcatfee | 6:a64d79286726 | 8 | * |
ziadeldebri | 3:b787aa49b900 | 9 | * Example: |
ziadeldebri | 3:b787aa49b900 | 10 | * @code |
ziadeldebri | 3:b787aa49b900 | 11 | * #include "mbed.h" |
ziadeldebri | 3:b787aa49b900 | 12 | * #include "Motor.h" |
Dogcatfee | 6:a64d79286726 | 13 | * #include "Servo.h" |
ziadeldebri | 3:b787aa49b900 | 14 | * Motor my_motor(P12,P13P,p11); |
Dogcatfee | 6:a64d79286726 | 15 | * Servo my_servo(p21,my_motor); |
Dogcatfee | 6:a64d79286726 | 16 | * |
ziadeldebri | 3:b787aa49b900 | 17 | * int main() { |
Dogcatfee | 6:a64d79286726 | 18 | * added .get() to approximate position |
ziadeldebri | 3:b787aa49b900 | 19 | * } |
ziadeldebri | 3:b787aa49b900 | 20 | * @endcode |
ziadeldebri | 3:b787aa49b900 | 21 | */ |
Dogcatfee | 6:a64d79286726 | 22 | class Servo { |
ziadeldebri | 3:b787aa49b900 | 23 | |
ziadeldebri | 3:b787aa49b900 | 24 | public: |
Dogcatfee | 6:a64d79286726 | 25 | /** Create a servo object. |
Dogcatfee | 6:a64d79286726 | 26 | * |
Dogcatfee | 6:a64d79286726 | 27 | * @param pin AnalogIn pin to be feedback, motor is a Motor object from Motor.h |
ziadeldebri | 3:b787aa49b900 | 28 | */ |
Dogcatfee | 6:a64d79286726 | 29 | Servo(PinName analog_input,PinName Positive, PinName Negative,PinName Speed); |
Dogcatfee | 6:a64d79286726 | 30 | |
Dogcatfee | 6:a64d79286726 | 31 | /** Set the servo position |
Dogcatfee | 6:a64d79286726 | 32 | * |
Dogcatfee | 6:a64d79286726 | 33 | * @param angle intger in degrees 0-180 to represent the full range. |
ziadeldebri | 3:b787aa49b900 | 34 | */ |
Dogcatfee | 6:a64d79286726 | 35 | void set(int degree); |
Dogcatfee | 6:a64d79286726 | 36 | |
Dogcatfee | 6:a64d79286726 | 37 | /** Read the servo current position in degrees from 0-180 |
Dogcatfee | 6:a64d79286726 | 38 | * |
Dogcatfee | 6:a64d79286726 | 39 | * @return returns the current anlge of the servo |
Dogcatfee | 6:a64d79286726 | 40 | */ |
Dogcatfee | 6:a64d79286726 | 41 | unsigned int get(); |
Dogcatfee | 6:a64d79286726 | 42 | void move(void); |
Dogcatfee | 6:a64d79286726 | 43 | |
Dogcatfee | 6:a64d79286726 | 44 | void check(); |
ziadeldebri | 3:b787aa49b900 | 45 | protected: |
Dogcatfee | 6:a64d79286726 | 46 | AnalogIn _feedback; |
Dogcatfee | 6:a64d79286726 | 47 | Motor _motor; |
Dogcatfee | 6:a64d79286726 | 48 | }; |
Dogcatfee | 6:a64d79286726 | 49 | |
Dogcatfee | 6:a64d79286726 | 50 | #endif |
Dogcatfee | 6:a64d79286726 | 51 |