![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Tp2
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_SimpleControls by
Servo.cpp@0:dfcebc1e442a, 2014-10-31 (annotated)
- Committer:
- RedBearLab
- Date:
- Fri Oct 31 09:41:40 2014 +0000
- Revision:
- 0:dfcebc1e442a
- Child:
- 1:f03072e32ed3
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RedBearLab | 0:dfcebc1e442a | 1 | #include "Servo.h" |
RedBearLab | 0:dfcebc1e442a | 2 | |
RedBearLab | 0:dfcebc1e442a | 3 | Servo::Servo(PinName pin) : _servo(pin) |
RedBearLab | 0:dfcebc1e442a | 4 | { |
RedBearLab | 0:dfcebc1e442a | 5 | _servo.period_ms(20); |
RedBearLab | 0:dfcebc1e442a | 6 | } |
RedBearLab | 0:dfcebc1e442a | 7 | |
RedBearLab | 0:dfcebc1e442a | 8 | Servo::~Servo(void) |
RedBearLab | 0:dfcebc1e442a | 9 | { |
RedBearLab | 0:dfcebc1e442a | 10 | |
RedBearLab | 0:dfcebc1e442a | 11 | } |
RedBearLab | 0:dfcebc1e442a | 12 | |
RedBearLab | 0:dfcebc1e442a | 13 | void Servo::write(unsigned char degree) |
RedBearLab | 0:dfcebc1e442a | 14 | { |
RedBearLab | 0:dfcebc1e442a | 15 | convert(degree); |
RedBearLab | 0:dfcebc1e442a | 16 | _servo.pulsewidth_us(pulse); |
RedBearLab | 0:dfcebc1e442a | 17 | } |
RedBearLab | 0:dfcebc1e442a | 18 | |
RedBearLab | 0:dfcebc1e442a | 19 | void Servo::convert(unsigned char degree) |
RedBearLab | 0:dfcebc1e442a | 20 | { |
RedBearLab | 0:dfcebc1e442a | 21 | // 0~180 degree correspond to 500~2500 |
RedBearLab | 0:dfcebc1e442a | 22 | pulse = degree * 11 + 500; |
RedBearLab | 0:dfcebc1e442a | 23 | } |