Grove temperature sensor library

Dependents:   Grove_Temp_Hello_world

Committer:
peipei123
Date:
Thu Mar 10 19:13:21 2016 +0000
Revision:
0:d47df95f4936
Child:
1:813f0d53a75c
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peipei123 0:d47df95f4936 1 /* mbed R/C Servo Library
peipei123 0:d47df95f4936 2 * Copyright (c) 2007-2010 sford, cstyles
peipei123 0:d47df95f4936 3 *
peipei123 0:d47df95f4936 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
peipei123 0:d47df95f4936 5 * of this software and associated documentation files (the "Software"), to deal
peipei123 0:d47df95f4936 6 * in the Software without restriction, including without limitation the rights
peipei123 0:d47df95f4936 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
peipei123 0:d47df95f4936 8 * copies of the Software, and to permit persons to whom the Software is
peipei123 0:d47df95f4936 9 * furnished to do so, subject to the following conditions:
peipei123 0:d47df95f4936 10 *
peipei123 0:d47df95f4936 11 * The above copyright notice and this permission notice shall be included in
peipei123 0:d47df95f4936 12 * all copies or substantial portions of the Software.
peipei123 0:d47df95f4936 13 *
peipei123 0:d47df95f4936 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
peipei123 0:d47df95f4936 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
peipei123 0:d47df95f4936 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
peipei123 0:d47df95f4936 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
peipei123 0:d47df95f4936 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
peipei123 0:d47df95f4936 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
peipei123 0:d47df95f4936 20 * THE SOFTWARE.
peipei123 0:d47df95f4936 21 */
peipei123 0:d47df95f4936 22
peipei123 0:d47df95f4936 23 #ifndef MBED_SERVO_H
peipei123 0:d47df95f4936 24 #define MBED_SERVO_H
peipei123 0:d47df95f4936 25
peipei123 0:d47df95f4936 26 #include "mbed.h"
peipei123 0:d47df95f4936 27
peipei123 0:d47df95f4936 28 /** Servo control class, based on a PwmOut
peipei123 0:d47df95f4936 29 *
peipei123 0:d47df95f4936 30 * Example:
peipei123 0:d47df95f4936 31 * @code
peipei123 0:d47df95f4936 32 * // Continuously sweep the servo through it's full range
peipei123 0:d47df95f4936 33 * #include "mbed.h"
peipei123 0:d47df95f4936 34 * #include "Servo.h"
peipei123 0:d47df95f4936 35 *
peipei123 0:d47df95f4936 36 * Servo myservo(p21);
peipei123 0:d47df95f4936 37 *
peipei123 0:d47df95f4936 38 * int main() {
peipei123 0:d47df95f4936 39 * while(1) {
peipei123 0:d47df95f4936 40 * for(int i=0; i<100; i++) {
peipei123 0:d47df95f4936 41 * myservo = i/100.0;
peipei123 0:d47df95f4936 42 * wait(0.01);
peipei123 0:d47df95f4936 43 * }
peipei123 0:d47df95f4936 44 * for(int i=100; i>0; i--) {
peipei123 0:d47df95f4936 45 * myservo = i/100.0;
peipei123 0:d47df95f4936 46 * wait(0.01);
peipei123 0:d47df95f4936 47 * }
peipei123 0:d47df95f4936 48 * }
peipei123 0:d47df95f4936 49 * }
peipei123 0:d47df95f4936 50 * @endcode
peipei123 0:d47df95f4936 51 */
peipei123 0:d47df95f4936 52 class Servo {
peipei123 0:d47df95f4936 53
peipei123 0:d47df95f4936 54 public:
peipei123 0:d47df95f4936 55 /** Create a servo object connected to the specified PwmOut pin
peipei123 0:d47df95f4936 56 *
peipei123 0:d47df95f4936 57 * @param pin PwmOut pin to connect to
peipei123 0:d47df95f4936 58 */
peipei123 0:d47df95f4936 59 Servo(PinName pin);
peipei123 0:d47df95f4936 60
peipei123 0:d47df95f4936 61 /** Set the servo position, normalised to it's full range
peipei123 0:d47df95f4936 62 *
peipei123 0:d47df95f4936 63 * @param percent A normalised number 0.0-1.0 to represent the full range.
peipei123 0:d47df95f4936 64 */
peipei123 0:d47df95f4936 65 void write(float percent);
peipei123 0:d47df95f4936 66
peipei123 0:d47df95f4936 67 /** Read the servo motors current position
peipei123 0:d47df95f4936 68 *
peipei123 0:d47df95f4936 69 * @param returns A normalised number 0.0-1.0 representing the full range.
peipei123 0:d47df95f4936 70 */
peipei123 0:d47df95f4936 71 float read();
peipei123 0:d47df95f4936 72
peipei123 0:d47df95f4936 73 /** Set the servo position
peipei123 0:d47df95f4936 74 *
peipei123 0:d47df95f4936 75 * @param degrees Servo position in degrees
peipei123 0:d47df95f4936 76 */
peipei123 0:d47df95f4936 77 void position(float degrees);
peipei123 0:d47df95f4936 78
peipei123 0:d47df95f4936 79 /** Allows calibration of the range and angles for a particular servo
peipei123 0:d47df95f4936 80 *
peipei123 0:d47df95f4936 81 * @param range Pulsewidth range from center (1.5ms) to maximum/minimum position in seconds
peipei123 0:d47df95f4936 82 * @param degrees Angle from centre to maximum/minimum position in degrees
peipei123 0:d47df95f4936 83 */
peipei123 0:d47df95f4936 84 void calibrate(float range = 0.0005, float degrees = 45.0);
peipei123 0:d47df95f4936 85
peipei123 0:d47df95f4936 86 /** Shorthand for the write and read functions */
peipei123 0:d47df95f4936 87 Servo& operator= (float percent);
peipei123 0:d47df95f4936 88 Servo& operator= (Servo& rhs);
peipei123 0:d47df95f4936 89 operator float();
peipei123 0:d47df95f4936 90
peipei123 0:d47df95f4936 91 protected:
peipei123 0:d47df95f4936 92 PwmOut _pwm;
peipei123 0:d47df95f4936 93 float _range;
peipei123 0:d47df95f4936 94 float _degrees;
peipei123 0:d47df95f4936 95 float _p;
peipei123 0:d47df95f4936 96 };
peipei123 0:d47df95f4936 97
peipei123 0:d47df95f4936 98 #endif