Nicolas Borla
/
PES2_mbed_os
PES2_mbed_os_6
Servo.cpp@2:87ca9b0c9992, 2021-03-13 (annotated)
- Committer:
- boro
- Date:
- Sat Mar 13 11:06:23 2021 +0100
- Revision:
- 2:87ca9b0c9992
updated to be compatible with mbed-os 6.8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
boro | 2:87ca9b0c9992 | 1 | #include "Servo.h" |
boro | 2:87ca9b0c9992 | 2 | #include "mbed.h" |
boro | 2:87ca9b0c9992 | 3 | |
boro | 2:87ca9b0c9992 | 4 | Servo::Servo(PinName Pin) : ServoPin(Pin) {} |
boro | 2:87ca9b0c9992 | 5 | |
boro | 2:87ca9b0c9992 | 6 | void Servo::SetPosition(int Pos) { |
boro | 2:87ca9b0c9992 | 7 | Position = Pos; |
boro | 2:87ca9b0c9992 | 8 | } |
boro | 2:87ca9b0c9992 | 9 | |
boro | 2:87ca9b0c9992 | 10 | void Servo::StartPulse() { |
boro | 2:87ca9b0c9992 | 11 | ServoPin = 1; |
boro | 2:87ca9b0c9992 | 12 | PulseStop.attach_us(callback(this, &Servo::EndPulse), Position); |
boro | 2:87ca9b0c9992 | 13 | } |
boro | 2:87ca9b0c9992 | 14 | |
boro | 2:87ca9b0c9992 | 15 | void Servo::EndPulse() { |
boro | 2:87ca9b0c9992 | 16 | ServoPin = 0; |
boro | 2:87ca9b0c9992 | 17 | } |
boro | 2:87ca9b0c9992 | 18 | |
boro | 2:87ca9b0c9992 | 19 | void Servo::Enable(int StartPos, int Period) { |
boro | 2:87ca9b0c9992 | 20 | Position = StartPos; |
boro | 2:87ca9b0c9992 | 21 | Pulse.attach_us(callback(this, &Servo::StartPulse), Period); |
boro | 2:87ca9b0c9992 | 22 | } |
boro | 2:87ca9b0c9992 | 23 | |
boro | 2:87ca9b0c9992 | 24 | void Servo::Disable() { |
boro | 2:87ca9b0c9992 | 25 | Pulse.detach(); |
boro | 2:87ca9b0c9992 | 26 | } |