Oliver Ainhirn
/
last_copy
versuch 2
servo.h@0:b74c2c5f64c1, 2019-06-24 (annotated)
- Committer:
- corsa1600
- Date:
- Mon Jun 24 05:33:30 2019 +0000
- Revision:
- 0:b74c2c5f64c1
versuch2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
corsa1600 | 0:b74c2c5f64c1 | 1 | //servo.h |
corsa1600 | 0:b74c2c5f64c1 | 2 | #ifndef MBED_SERVO_H |
corsa1600 | 0:b74c2c5f64c1 | 3 | #define MBED_SERVO_H |
corsa1600 | 0:b74c2c5f64c1 | 4 | |
corsa1600 | 0:b74c2c5f64c1 | 5 | #include "mbed.h" |
corsa1600 | 0:b74c2c5f64c1 | 6 | |
corsa1600 | 0:b74c2c5f64c1 | 7 | class Servo |
corsa1600 | 0:b74c2c5f64c1 | 8 | { |
corsa1600 | 0:b74c2c5f64c1 | 9 | |
corsa1600 | 0:b74c2c5f64c1 | 10 | public: |
corsa1600 | 0:b74c2c5f64c1 | 11 | // Create a servo object connected to the specified PwmOut pin |
corsa1600 | 0:b74c2c5f64c1 | 12 | Servo(PinName pin); |
corsa1600 | 0:b74c2c5f64c1 | 13 | |
corsa1600 | 0:b74c2c5f64c1 | 14 | //** Set the servo position, normalised to it's full range |
corsa1600 | 0:b74c2c5f64c1 | 15 | void write(float percent); |
corsa1600 | 0:b74c2c5f64c1 | 16 | |
corsa1600 | 0:b74c2c5f64c1 | 17 | //** Read the servo motors current position |
corsa1600 | 0:b74c2c5f64c1 | 18 | float read(); |
corsa1600 | 0:b74c2c5f64c1 | 19 | |
corsa1600 | 0:b74c2c5f64c1 | 20 | //** Set the servo position |
corsa1600 | 0:b74c2c5f64c1 | 21 | void position(float degrees); |
corsa1600 | 0:b74c2c5f64c1 | 22 | |
corsa1600 | 0:b74c2c5f64c1 | 23 | //** Allows calibration of the range and angles for a particular servo |
corsa1600 | 0:b74c2c5f64c1 | 24 | void calibrate(float range = 0.0005, float degrees = 45.0); |
corsa1600 | 0:b74c2c5f64c1 | 25 | |
corsa1600 | 0:b74c2c5f64c1 | 26 | /** Shorthand for the write and read functions */ |
corsa1600 | 0:b74c2c5f64c1 | 27 | Servo& operator= (float percent); |
corsa1600 | 0:b74c2c5f64c1 | 28 | Servo& operator= (Servo& rhs); |
corsa1600 | 0:b74c2c5f64c1 | 29 | operator float(); |
corsa1600 | 0:b74c2c5f64c1 | 30 | |
corsa1600 | 0:b74c2c5f64c1 | 31 | protected: |
corsa1600 | 0:b74c2c5f64c1 | 32 | PwmOut _pwm; |
corsa1600 | 0:b74c2c5f64c1 | 33 | float _range; |
corsa1600 | 0:b74c2c5f64c1 | 34 | float _degrees; |
corsa1600 | 0:b74c2c5f64c1 | 35 | float _p; |
corsa1600 | 0:b74c2c5f64c1 | 36 | }; |
corsa1600 | 0:b74c2c5f64c1 | 37 | |
corsa1600 | 0:b74c2c5f64c1 | 38 | #endif |