Servogoeie

Dependents:   Servoaansturing

Committer:
Renate
Date:
Tue Nov 05 16:08:54 2019 +0000
Revision:
0:8038a8c122fd
Deels al servo toegevoegd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Renate 0:8038a8c122fd 1 #include "Servo.h"
Renate 0:8038a8c122fd 2 #include "mbed.h"
Renate 0:8038a8c122fd 3
Renate 0:8038a8c122fd 4 Servo::Servo(PinName Pin) : ServoPin(Pin) {}
Renate 0:8038a8c122fd 5
Renate 0:8038a8c122fd 6 void Servo::SetPosition(int Pos) {
Renate 0:8038a8c122fd 7 Position = Pos;
Renate 0:8038a8c122fd 8 }
Renate 0:8038a8c122fd 9
Renate 0:8038a8c122fd 10 void Servo::StartPulse() {
Renate 0:8038a8c122fd 11 ServoPin = 1;
Renate 0:8038a8c122fd 12 PulseStop.attach_us(this, &Servo::EndPulse, Position);
Renate 0:8038a8c122fd 13 }
Renate 0:8038a8c122fd 14
Renate 0:8038a8c122fd 15 void Servo::EndPulse() {
Renate 0:8038a8c122fd 16 ServoPin = 0;
Renate 0:8038a8c122fd 17 }
Renate 0:8038a8c122fd 18
Renate 0:8038a8c122fd 19 void Servo::Enable(int StartPos, int Period) {
Renate 0:8038a8c122fd 20 Position = StartPos;
Renate 0:8038a8c122fd 21 Pulse.attach_us(this, &Servo::StartPulse, Period);
Renate 0:8038a8c122fd 22 }
Renate 0:8038a8c122fd 23
Renate 0:8038a8c122fd 24 void Servo::Disable() {
Renate 0:8038a8c122fd 25 Pulse.detach();
Renate 0:8038a8c122fd 26 }