PM2_Lib
Dependencies: LSM9DS1 RangeFinder FastPWM
Servo.h@22:13db7047054c, 2022-03-23 (annotated)
- Committer:
- pmic
- Date:
- Wed Mar 23 09:36:59 2022 +0000
- Revision:
- 22:13db7047054c
- Parent:
- 21:45d903d986f6
- Child:
- 23:1926540ebbec
Added SetPeriod function in Servo class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pmic | 0:86129f1b4a93 | 1 | /* mbed Servo Library without using PWM pins |
pmic | 0:86129f1b4a93 | 2 | * Copyright (c) 2010 Jasper Denkers |
pmic | 0:86129f1b4a93 | 3 | * |
pmic | 0:86129f1b4a93 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
pmic | 0:86129f1b4a93 | 5 | * of this software and associated documentation files (the "Software"), to deal |
pmic | 0:86129f1b4a93 | 6 | * in the Software without restriction, including without limitation the rights |
pmic | 0:86129f1b4a93 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
pmic | 0:86129f1b4a93 | 8 | * copies of the Software, and to permit persons to whom the Software is |
pmic | 0:86129f1b4a93 | 9 | * furnished to do so, subject to the following conditions: |
pmic | 0:86129f1b4a93 | 10 | * |
pmic | 0:86129f1b4a93 | 11 | * The above copyright notice and this permission notice shall be included in |
pmic | 0:86129f1b4a93 | 12 | * all copies or substantial portions of the Software. |
pmic | 0:86129f1b4a93 | 13 | * |
pmic | 0:86129f1b4a93 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
pmic | 0:86129f1b4a93 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
pmic | 0:86129f1b4a93 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
pmic | 0:86129f1b4a93 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
pmic | 0:86129f1b4a93 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
pmic | 0:86129f1b4a93 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
pmic | 0:86129f1b4a93 | 20 | * THE SOFTWARE. |
pmic | 0:86129f1b4a93 | 21 | */ |
pmic | 0:86129f1b4a93 | 22 | |
pmic | 0:86129f1b4a93 | 23 | #ifndef MBED_SERVO_H |
pmic | 0:86129f1b4a93 | 24 | #define MBED_SERVO_H |
pmic | 0:86129f1b4a93 | 25 | |
pmic | 10:fe74e8909d3f | 26 | #include "mbed.h" |
pmic | 10:fe74e8909d3f | 27 | |
pmic | 4:9c003c402033 | 28 | class Servo |
pmic | 4:9c003c402033 | 29 | { |
pmic | 0:86129f1b4a93 | 30 | |
pmic | 0:86129f1b4a93 | 31 | public: |
pmic | 16:69911e81dfd4 | 32 | |
pmic | 0:86129f1b4a93 | 33 | Servo(PinName Pin); |
pmic | 22:13db7047054c | 34 | void Servo::SetPeriod(float _Period); |
pmic | 16:69911e81dfd4 | 35 | void SetPosition(float _Input); |
pmic | 16:69911e81dfd4 | 36 | void Enable(float _StartInput, int _Period); |
pmic | 21:45d903d986f6 | 37 | void ReEnable(); |
pmic | 0:86129f1b4a93 | 38 | void Disable(); |
pmic | 20:ea222b81350e | 39 | bool isEnabled(); |
pmic | 0:86129f1b4a93 | 40 | |
pmic | 0:86129f1b4a93 | 41 | private: |
pmic | 18:21c0a669d6ef | 42 | |
pmic | 18:21c0a669d6ef | 43 | static const float MIN_INPUT; |
pmic | 18:21c0a669d6ef | 44 | static const float MAX_INPUT; |
pmic | 18:21c0a669d6ef | 45 | |
pmic | 0:86129f1b4a93 | 46 | void StartPulse(); |
pmic | 0:86129f1b4a93 | 47 | void EndPulse(); |
pmic | 0:86129f1b4a93 | 48 | |
pmic | 20:ea222b81350e | 49 | bool servoEnabled; |
pmic | 16:69911e81dfd4 | 50 | int Position, Period; |
pmic | 0:86129f1b4a93 | 51 | DigitalOut ServoPin; |
pmic | 0:86129f1b4a93 | 52 | Ticker Pulse; |
pmic | 0:86129f1b4a93 | 53 | Timeout PulseStop; |
pmic | 0:86129f1b4a93 | 54 | }; |
pmic | 0:86129f1b4a93 | 55 | |
pmic | 0:86129f1b4a93 | 56 | #endif |