
Diseño de Firmaware Diseañado en base a los requerimientos definidos durante la etapa de analisis.
Fork of nRF51822_SimpleControls by
Servo.cpp@0:58e350255405, 2016-02-22 (annotated)
- Committer:
- dixysleo
- Date:
- Mon Feb 22 15:26:37 2016 +0000
- Revision:
- 0:58e350255405
nRF51822_SimpleControls
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dixysleo | 0:58e350255405 | 1 | /* |
dixysleo | 0:58e350255405 | 2 | |
dixysleo | 0:58e350255405 | 3 | Copyright (c) 2012-2014 RedBearLab |
dixysleo | 0:58e350255405 | 4 | |
dixysleo | 0:58e350255405 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
dixysleo | 0:58e350255405 | 6 | and associated documentation files (the "Software"), to deal in the Software without restriction, |
dixysleo | 0:58e350255405 | 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
dixysleo | 0:58e350255405 | 8 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, |
dixysleo | 0:58e350255405 | 9 | subject to the following conditions: |
dixysleo | 0:58e350255405 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
dixysleo | 0:58e350255405 | 11 | |
dixysleo | 0:58e350255405 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
dixysleo | 0:58e350255405 | 13 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
dixysleo | 0:58e350255405 | 14 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
dixysleo | 0:58e350255405 | 15 | FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
dixysleo | 0:58e350255405 | 16 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
dixysleo | 0:58e350255405 | 17 | |
dixysleo | 0:58e350255405 | 18 | */ |
dixysleo | 0:58e350255405 | 19 | |
dixysleo | 0:58e350255405 | 20 | #include "Servo.h" |
dixysleo | 0:58e350255405 | 21 | |
dixysleo | 0:58e350255405 | 22 | Servo::Servo(PinName pin) : _servo(pin) |
dixysleo | 0:58e350255405 | 23 | { |
dixysleo | 0:58e350255405 | 24 | _servo.period_ms(20); |
dixysleo | 0:58e350255405 | 25 | } |
dixysleo | 0:58e350255405 | 26 | |
dixysleo | 0:58e350255405 | 27 | Servo::~Servo(void) |
dixysleo | 0:58e350255405 | 28 | { |
dixysleo | 0:58e350255405 | 29 | |
dixysleo | 0:58e350255405 | 30 | } |
dixysleo | 0:58e350255405 | 31 | |
dixysleo | 0:58e350255405 | 32 | void Servo::write(unsigned char degree) |
dixysleo | 0:58e350255405 | 33 | { |
dixysleo | 0:58e350255405 | 34 | convert(degree); |
dixysleo | 0:58e350255405 | 35 | _servo.pulsewidth_us(pulse); |
dixysleo | 0:58e350255405 | 36 | } |
dixysleo | 0:58e350255405 | 37 | |
dixysleo | 0:58e350255405 | 38 | void Servo::convert(unsigned char degree) |
dixysleo | 0:58e350255405 | 39 | { |
dixysleo | 0:58e350255405 | 40 | // 0~180 degree correspond to 500~2500 |
dixysleo | 0:58e350255405 | 41 | pulse = degree * 11 + 500; |
dixysleo | 0:58e350255405 | 42 | } |