![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
project Internet of things 2016 UPMC : based on simple controls, it sends pression and temperature from BMP180
Dependencies: BLE_API BMP180 mbed nRF51822
Servo.cpp@0:05113982163d, 2017-01-02 (annotated)
- Committer:
- quentin93
- Date:
- Mon Jan 02 22:10:20 2017 +0000
- Revision:
- 0:05113982163d
project Internet of things 2016 UPMC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
quentin93 | 0:05113982163d | 1 | /* |
quentin93 | 0:05113982163d | 2 | |
quentin93 | 0:05113982163d | 3 | Copyright (c) 2012-2014 RedBearLab |
quentin93 | 0:05113982163d | 4 | |
quentin93 | 0:05113982163d | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
quentin93 | 0:05113982163d | 6 | and associated documentation files (the "Software"), to deal in the Software without restriction, |
quentin93 | 0:05113982163d | 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
quentin93 | 0:05113982163d | 8 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, |
quentin93 | 0:05113982163d | 9 | subject to the following conditions: |
quentin93 | 0:05113982163d | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
quentin93 | 0:05113982163d | 11 | |
quentin93 | 0:05113982163d | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
quentin93 | 0:05113982163d | 13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
quentin93 | 0:05113982163d | 14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
quentin93 | 0:05113982163d | 15 | FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
quentin93 | 0:05113982163d | 16 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
quentin93 | 0:05113982163d | 17 | |
quentin93 | 0:05113982163d | 18 | */ |
quentin93 | 0:05113982163d | 19 | |
quentin93 | 0:05113982163d | 20 | #include "Servo.h" |
quentin93 | 0:05113982163d | 21 | |
quentin93 | 0:05113982163d | 22 | Servo::Servo(PinName pin) : _servo(pin) |
quentin93 | 0:05113982163d | 23 | { |
quentin93 | 0:05113982163d | 24 | _servo.period_ms(20); |
quentin93 | 0:05113982163d | 25 | } |
quentin93 | 0:05113982163d | 26 | |
quentin93 | 0:05113982163d | 27 | Servo::~Servo(void) |
quentin93 | 0:05113982163d | 28 | { |
quentin93 | 0:05113982163d | 29 | |
quentin93 | 0:05113982163d | 30 | } |
quentin93 | 0:05113982163d | 31 | |
quentin93 | 0:05113982163d | 32 | void Servo::write(unsigned char degree) |
quentin93 | 0:05113982163d | 33 | { |
quentin93 | 0:05113982163d | 34 | convert(degree); |
quentin93 | 0:05113982163d | 35 | _servo.pulsewidth_us(pulse); |
quentin93 | 0:05113982163d | 36 | } |
quentin93 | 0:05113982163d | 37 | |
quentin93 | 0:05113982163d | 38 | void Servo::convert(unsigned char degree) |
quentin93 | 0:05113982163d | 39 | { |
quentin93 | 0:05113982163d | 40 | // 0~180 degree correspond to 500~2500 |
quentin93 | 0:05113982163d | 41 | pulse = degree * 11 + 500; |
quentin93 | 0:05113982163d | 42 | } |