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