servom

Dependents:   servomotore progetto8 progetto9 progetto10 ... more

Committer:
faraonemena
Date:
Thu Mar 28 15:52:51 2019 +0000
Revision:
1:de53826667ce
servom

Who changed what in which revision?

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