Simply creates a servo object from a motor object, to allow the control of the angle. uses the solar panel to look for the brightest spot, then stops.
Dependencies: mbed
Fork of Lab6_Basic by
Servo.h@2:3540e1f2f0e1, 2016-08-17 (annotated)
- Committer:
- ziadeldebri
- Date:
- Wed Aug 17 19:21:43 2016 +0000
- Revision:
- 2:3540e1f2f0e1
- Parent:
- 1:aa0b85d0961c
- Child:
- 3:b787aa49b900
more comments
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 | 0:61b18b631f94 | 3 | |
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 | 0:61b18b631f94 | 15 | * Servo myservo(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 | 0:61b18b631f94 | 29 | Servo(PinName pin,Motor motor); |
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 | 0:61b18b631f94 | 35 | void write(float percent); |
ziadeldebri | 0:61b18b631f94 | 36 | |
ziadeldebri | 0:61b18b631f94 | 37 | /** Read the servo current position in degrees from 0-180 |
ziadeldebri | 0:61b18b631f94 | 38 | * |
ziadeldebri | 0:61b18b631f94 | 39 | * @param returns the current anlge of the servo |
ziadeldebri | 0:61b18b631f94 | 40 | */ |
ziadeldebri | 0:61b18b631f94 | 41 | int read(); |
ziadeldebri | 0:61b18b631f94 | 42 | |
ziadeldebri | 0:61b18b631f94 | 43 | protected: |
ziadeldebri | 0:61b18b631f94 | 44 | AnalogIn _feedback; |
ziadeldebri | 0:61b18b631f94 | 45 | }; |
ziadeldebri | 0:61b18b631f94 | 46 | |
ziadeldebri | 0:61b18b631f94 | 47 | #endif |
ziadeldebri | 0:61b18b631f94 | 48 |