My fully self designed first stable working Quadrocopter Software.

Dependencies:   mbed

Dependents:   fluy343

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Servo_PWM.cpp Source File

Servo_PWM.cpp

00001 #include "Servo_PWM.h"
00002 #include "mbed.h"
00003 
00004 Servo_PWM::Servo_PWM(PinName Pin, int frequency) : ServoPin(Pin) {
00005     SetFrequency(frequency);
00006     ServoPin = 0;
00007     // initialize ESC
00008     SetPosition(0);  // zero throttle
00009 }
00010 
00011 void Servo_PWM::SetFrequency(int frequency) {
00012     ServoPin.period(1.0/frequency);
00013 }
00014 
00015 void Servo_PWM::SetPosition(int position) {
00016     if (position > 1000)
00017         position = 1000;
00018     if (position < 0)
00019         position = 0;
00020     ServoPin.pulsewidth_us(position+1000);
00021 }
00022 
00023 void Servo_PWM::operator=(int position) {
00024     SetPosition(position);
00025 }