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.
Fork of Lab6_Basic by
Servo.h@8:c2f0e524696b, 2016-11-19 (annotated)
- Committer:
- Dogcatfee
- Date:
- Sat Nov 19 09:10:23 2016 +0000
- Revision:
- 8:c2f0e524696b
- Parent:
- 3:b787aa49b900
Fixed the Motor header;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ziadeldebri | 0:61b18b631f94 | 1 | #include "Motor.h" |
| ziadeldebri | 0:61b18b631f94 | 2 | #include "mbed.h" |
| ziadeldebri | 3:b787aa49b900 | 3 | #include "SLCD.h" |
| ziadeldebri | 0:61b18b631f94 | 4 | #ifndef MBED_SERVO_H |
| ziadeldebri | 0:61b18b631f94 | 5 | #define MBED_SERVO_H |
| ziadeldebri | 0:61b18b631f94 | 6 | |
| ziadeldebri | 0:61b18b631f94 | 7 | /** Servo control class, based on a Motor Class object |
| ziadeldebri | 0:61b18b631f94 | 8 | * |
| ziadeldebri | 0:61b18b631f94 | 9 | * Example: |
| ziadeldebri | 0:61b18b631f94 | 10 | * @code |
| ziadeldebri | 0:61b18b631f94 | 11 | * #include "mbed.h" |
| ziadeldebri | 0:61b18b631f94 | 12 | * #include "Motor.h" |
| ziadeldebri | 0:61b18b631f94 | 13 | * #include "Servo.h" |
| ziadeldebri | 0:61b18b631f94 | 14 | * Motor my_motor(P12,P13P,p11); |
| ziadeldebri | 3:b787aa49b900 | 15 | * Servo my_servo(p21,my_motor); |
| ziadeldebri | 0:61b18b631f94 | 16 | * |
| ziadeldebri | 0:61b18b631f94 | 17 | * int main() { |
| ziadeldebri | 0:61b18b631f94 | 18 | * |
| ziadeldebri | 0:61b18b631f94 | 19 | * } |
| ziadeldebri | 0:61b18b631f94 | 20 | * @endcode |
| ziadeldebri | 0:61b18b631f94 | 21 | */ |
| ziadeldebri | 0:61b18b631f94 | 22 | class Servo { |
| ziadeldebri | 0:61b18b631f94 | 23 | |
| ziadeldebri | 0:61b18b631f94 | 24 | public: |
| ziadeldebri | 1:aa0b85d0961c | 25 | /** Create a servo object. |
| ziadeldebri | 0:61b18b631f94 | 26 | * |
| ziadeldebri | 2:3540e1f2f0e1 | 27 | * @param pin AnalogIn pin to be feedback, motor is a Motor object from Motor.h |
| ziadeldebri | 0:61b18b631f94 | 28 | */ |
| ziadeldebri | 3:b787aa49b900 | 29 | Servo(PinName analog_input,PinName Positive, PinName Negative,PinName Speed); |
| ziadeldebri | 0:61b18b631f94 | 30 | |
| ziadeldebri | 2:3540e1f2f0e1 | 31 | /** Set the servo position |
| ziadeldebri | 0:61b18b631f94 | 32 | * |
| ziadeldebri | 2:3540e1f2f0e1 | 33 | * @param angle intger in degrees 0-180 to represent the full range. |
| ziadeldebri | 0:61b18b631f94 | 34 | */ |
| ziadeldebri | 3:b787aa49b900 | 35 | void set(int degree); |
| ziadeldebri | 0:61b18b631f94 | 36 | |
| ziadeldebri | 0:61b18b631f94 | 37 | /** Read the servo current position in degrees from 0-180 |
| ziadeldebri | 0:61b18b631f94 | 38 | * |
| ziadeldebri | 3:b787aa49b900 | 39 | * @return returns the current anlge of the servo |
| ziadeldebri | 3:b787aa49b900 | 40 | */ |
| Dogcatfee | 8:c2f0e524696b | 41 | unsigned int get(); |
| ziadeldebri | 3:b787aa49b900 | 42 | void move(void); |
| ziadeldebri | 3:b787aa49b900 | 43 | |
| ziadeldebri | 3:b787aa49b900 | 44 | void check(); |
| ziadeldebri | 0:61b18b631f94 | 45 | protected: |
| ziadeldebri | 0:61b18b631f94 | 46 | AnalogIn _feedback; |
| ziadeldebri | 3:b787aa49b900 | 47 | Motor _motor; |
| ziadeldebri | 0:61b18b631f94 | 48 | }; |
| ziadeldebri | 0:61b18b631f94 | 49 | |
| ziadeldebri | 0:61b18b631f94 | 50 | #endif |
| ziadeldebri | 0:61b18b631f94 | 51 |
