Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LSM9DS1 RangeFinder FastPWM
Dependents: PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board ... more
Servo.cpp@0:86129f1b4a93, 2021-03-30 (annotated)
- Committer:
- pmic
- Date:
- Tue Mar 30 12:21:00 2021 +0000
- Revision:
- 0:86129f1b4a93
- Child:
- 4:9c003c402033
First commit.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pmic | 0:86129f1b4a93 | 1 | #include "Servo.h" |
| pmic | 0:86129f1b4a93 | 2 | #include "mbed.h" |
| pmic | 0:86129f1b4a93 | 3 | |
| pmic | 0:86129f1b4a93 | 4 | Servo::Servo(PinName Pin) : ServoPin(Pin) {} |
| pmic | 0:86129f1b4a93 | 5 | |
| pmic | 0:86129f1b4a93 | 6 | void Servo::SetPosition(int Pos) { |
| pmic | 0:86129f1b4a93 | 7 | Position = Pos; |
| pmic | 0:86129f1b4a93 | 8 | } |
| pmic | 0:86129f1b4a93 | 9 | |
| pmic | 0:86129f1b4a93 | 10 | void Servo::StartPulse() { |
| pmic | 0:86129f1b4a93 | 11 | ServoPin = 1; |
| pmic | 0:86129f1b4a93 | 12 | PulseStop.attach_us(callback(this, &Servo::EndPulse), Position); |
| pmic | 0:86129f1b4a93 | 13 | } |
| pmic | 0:86129f1b4a93 | 14 | |
| pmic | 0:86129f1b4a93 | 15 | void Servo::EndPulse() { |
| pmic | 0:86129f1b4a93 | 16 | ServoPin = 0; |
| pmic | 0:86129f1b4a93 | 17 | } |
| pmic | 0:86129f1b4a93 | 18 | |
| pmic | 0:86129f1b4a93 | 19 | void Servo::Enable(int StartPos, int Period) { |
| pmic | 0:86129f1b4a93 | 20 | Position = StartPos; |
| pmic | 0:86129f1b4a93 | 21 | Pulse.attach_us(callback(this, &Servo::StartPulse), Period); |
| pmic | 0:86129f1b4a93 | 22 | } |
| pmic | 0:86129f1b4a93 | 23 | |
| pmic | 0:86129f1b4a93 | 24 | void Servo::Disable() { |
| pmic | 0:86129f1b4a93 | 25 | Pulse.detach(); |
| pmic | 0:86129f1b4a93 | 26 | } |
