Test
Servo.cpp@0:2092473cf8c4, 2021-01-11 (annotated)
- Committer:
- fermedicius
- Date:
- Mon Jan 11 11:02:01 2021 +0000
- Revision:
- 0:2092473cf8c4
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fermedicius | 0:2092473cf8c4 | 1 | #include "Servo.h" |
fermedicius | 0:2092473cf8c4 | 2 | #include "mbed.h" |
fermedicius | 0:2092473cf8c4 | 3 | |
fermedicius | 0:2092473cf8c4 | 4 | Servo::Servo(PinName Pin) : ServoPin(Pin) { |
fermedicius | 0:2092473cf8c4 | 5 | |
fermedicius | 0:2092473cf8c4 | 6 | |
fermedicius | 0:2092473cf8c4 | 7 | } |
fermedicius | 0:2092473cf8c4 | 8 | void Servo::SetPosition(int Pos) { |
fermedicius | 0:2092473cf8c4 | 9 | Position = Pos; |
fermedicius | 0:2092473cf8c4 | 10 | } |
fermedicius | 0:2092473cf8c4 | 11 | |
fermedicius | 0:2092473cf8c4 | 12 | void Servo::StartPulse() { |
fermedicius | 0:2092473cf8c4 | 13 | ServoPin = 1; |
fermedicius | 0:2092473cf8c4 | 14 | PulseStop.attach_us(this, &Servo::EndPulse, Position); |
fermedicius | 0:2092473cf8c4 | 15 | } |
fermedicius | 0:2092473cf8c4 | 16 | |
fermedicius | 0:2092473cf8c4 | 17 | void Servo::EndPulse() { |
fermedicius | 0:2092473cf8c4 | 18 | ServoPin = 0; |
fermedicius | 0:2092473cf8c4 | 19 | } |
fermedicius | 0:2092473cf8c4 | 20 | |
fermedicius | 0:2092473cf8c4 | 21 | void Servo::Enable(int StartPos, int Period) { |
fermedicius | 0:2092473cf8c4 | 22 | Position = StartPos; |
fermedicius | 0:2092473cf8c4 | 23 | Pulse.attach_us(this, &Servo::StartPulse, Period); |
fermedicius | 0:2092473cf8c4 | 24 | } |
fermedicius | 0:2092473cf8c4 | 25 | |
fermedicius | 0:2092473cf8c4 | 26 | void Servo::Disable() { |
fermedicius | 0:2092473cf8c4 | 27 | Pulse.detach(); |
fermedicius | 0:2092473cf8c4 | 28 | } |